https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103699

--- Comment #2 from Petr <kobalicek.petr at gmail dot com> ---
If you compile this with clang the function test_u32() will corretly return the
expected 0xBBCCDDEE and not 0x0708090A.

If you compile with older GCC, like GCC 10, the test would also return
0xBBCCDDEE. Only GCC-11 and upward return 0x0708090A.

Based on the documentation here:

https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#Common-Variable-Attributes

It's stated that "When used as part of a typedef, the aligned attribute can
both increase and decrease alignment, and specifying the packed attribute
generates a warning." - it explicitly allows to create a type with lower
alignment, so I don't consider this undefined behavior - in general UBSAN is
fine with this construct.

Reply via email to