https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107431
Martin Liška <marxin at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> --- > % cat example2.c > int main() { > int a=2; > int b=1; > long *c = &b; > long d = *c; > &a; > } Well, in this case you are lucky and 'b' is aligned to 8-bytes: __builtin_printf ("&b=%p\n", &b); $ gcc-12 example2.c -fsanitize=undefined -w && ./a.out &b=0x7fffffffd438 $ gcc-12 -O1 example2.c -fsanitize=undefined -w && ./a.out &b=0x7fffffffd44c example2.c:6:10: runtime error: load of misaligned address 0x7fffffffd44c for type 'long int', which requires 8 byte alignment 0x7fffffffd44c: note: pointer points here 67 6c 69 62 01 00 00 00 68 d5 ff ff ff 7f 00 00 b0 c5 62 f7 ff 7f 00 00 50 d5 ff ff ff 7f 00 00 ^ example2.c:6:10: runtime error: load of address 0x7fffffffd44c with insufficient space for an object of type 'int' 0x7fffffffd44c: note: pointer points here 67 6c 69 62 01 00 00 00 68 d5 ff ff ff 7f 00 00 b0 c5 62 f7 ff 7f 00 00 50 d5 ff ff ff 7f 00 00 ^ So nothing we can do about it.