https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105141
Bug ID: 105141 Summary: #pragma pack(1) causes incorrect UBSAN warning Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: shaohua.li at inf dot ethz.ch CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org Target Milestone: --- For the following code, UBSAN would warn a "load of misaligned address". Removing #pragma pack(1) will make the warning away. $cat a.c #pragma pack(1) struct { char a; int b; } c; int *d = &c.b; int main() { __builtin_printf("%d\n", *d); } $ $gcc -fsanitize=undefined -O0 -w a.c;./a.out ~/a.c:8:5: runtime error: load of misaligned address 0x0000004040ca for type 'int', which requires 4 byte alignment 0x0000004040ca: note: pointer points here 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ 0 $ $