https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119253
Dusan Stojkovic <dusan.stojko...@rt-rk.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|INVALID |FIXED --- Comment #2 from Dusan Stojkovic <dusan.stojko...@rt-rk.com> --- (In reply to Andrew Pinski from comment #1) > >replicates the unaligned 32-bit > >(uint32_t *)(flag_buf + (bit_pos >> 3)) > > > Yes because this is undefined code. You need to use either a type which has > an alignment of 1 or use memcpy (without a cast to the pointer of an aligned > type). Looking at the compiler warnings, this could be something to consider: * -Wall doesn't warn that this is undefined code; * -Wextra doesn't warn that this is undefined code; * -Wcast-align is the only case when this warning is written: warning: cast increases required alignment of target type [-Wcast-align] 122 | (*(uint32_t *)(flag_buf + (bit_pos >> 3))) >> (bit_pos & 7); But it's not enabled by default: # gcc -Q --help=warnings | grep cast-align -Wcast-align [disabled] -Wcast-align=strict [disabled] Maybe something to consider when compiling with -Wall -mstrict-align or -mvector-strict-align is to have these warnings enabled.