[Bug sanitizer/107431] UBSan has inconsistent behaviors in certain code snippet

2022-10-27 Thread shaohua.li at inf dot ethz.ch via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107431

--- Comment #2 from Li Shaohua  ---
Thanks a lot for the prompt reply!

[Bug sanitizer/107431] UBSan has inconsistent behaviors in certain code snippet

2022-10-27 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107431

Martin Liška  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #1 from Martin Liška  ---
> % cat example2.c
> int main() {
> int a=2;
> int b=1;
> long *c = 
> long d = *c;
> 
> }

Well, in this case you are lucky and 'b' is aligned to 8-bytes:
__builtin_printf ("=%p\n", );

$ gcc-12 example2.c -fsanitize=undefined -w && ./a.out
=0x7fffd438

$ gcc-12 -O1 example2.c -fsanitize=undefined -w && ./a.out
=0x7fffd44c
example2.c:6:10: runtime error: load of misaligned address 0x7fffd44c for
type 'long int', which requires 8 byte alignment
0x7fffd44c: 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 0x7fffd44c with
insufficient space for an object of type 'int'
0x7fffd44c: 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.