### Reproducertypedef __attribute__((aligned(4))) uint8_t uint8_aligned_t;static uint8_t test_sizeof(void){ uint8_t a = 0x42; uint8_aligned_t x[5]; uint8_t b = 0x41; for (uint8_t i = 0; i < sizeof(x); i++) { x[i] = i; } return a + b;}### Observationsizeof(uint8_aligned_t) == 1sizeof(x) == 8However, only 5 bytes are reserved on the stack for x. The actual stack layout produced by the compiler is:b | x[0..4] | pad | pad | aThe loop runs 8 iterations; the extra writes overwrite the padding bytes and a.### Questions- Why does sizeof(x) evaluate to 8 when sizeof(uint8_aligned_t) is 1 and the array has 5 elements?- Why does armclang reserve only 5 bytes of stack for x while simultaneously reporting sizeof(x) == 8? The two values disagree, and the trailing 3 bytes overlap an unrelated live local (a), so any sizeof(x)-driven loop silently corrupts memory ### NoteAligning the array variable instead of the element typedef behaves consistently (sizeof(x) == 5, alignment 4, no overrun):uint8_t x[5] __attribute__((aligned(4)));
Moving to the compiler forum where this should get better visibility.
If you have a valid support agreement, you can open a support case from the menu below which will go directly to dedicated engineers for this.