Following error shows while compilation process:
ccm.c:152:5: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
HWREG(AES_AES_IV_0) = ((uint32_t *)&ui8A0)[0];
ccm.c:325:5: error: dereferencing type-punned pointer will break strict- aliasing rules [-Werror=strict-aliasing]
((uint32_t *)&ui8MIC)[0] = HWREG(AES_AES_TAG_OUT_0);
Line 152-155:
HWREG(AES_AES_IV_0) = ((uint32_t *)&ui8A0)[0];
HWREG(AES_AES_IV_1) = ((uint32_t *)&ui8A0)[1];
HWREG(AES_AES_IV_2) = ((uint32_t *)&ui8A0)[2];
HWREG(AES_AES_IV_3) = ((uint32_t *)&ui8A0)[3];
ui8A0
is 16-sized uint8_t array:
uint8_t ui8A0[16];
Line 325-328:
((uint32_t *)&ui8MIC)[0] = HWREG(AES_AES_TAG_OUT_0);
((uint32_t *)&ui8MIC)[1] = HWREG(AES_AES_TAG_OUT_1);
((uint32_t *)&ui8MIC)[2] = HWREG(AES_AES_TAG_OUT_2);
((uint32_t *)&ui8MIC)[3] = HWREG(AES_AES_TAG_OUT_3);
ui8MIC
is 16-sized uint8_t array:
uint8_t volatile ui8MIC[16];
HWREG macro looks like this:
#define HWREG(x) \
(*((volatile uint32_t *)(x)))
That's how I understand it:
ui8A0
is an array, &ui8A0
is an address of first element, (uint32_t *)&ui8A0
is an address for array where elements are uint32_t contrary to uint8_t which were before, ((uint32_t *)&ui8A0)[0]
is the value of first element of an array which elements are uint32_t.
So basically this code has to pass 4 elements of ui8A0
to HWREG
macro.
It looks like this problem: https://stackoverflow.com/a/20956250/1625856 But I would prefer not to use the union-based solution.
Is there any other, easier way to handle it?
My only idea is to replace:
HWREG(AES_AES_IV_1) = ((uint32_t *)&ui8A0)[1];
with:
HWREG(AES_AES_IV_1) = (uintptr_t)&ui8A0[4];