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

--- Comment #2 from Zhendong Su <zhendong.su at inf dot ethz.ch> ---
(In reply to Drea Pinski from comment #1)
> struct b {
>   int c[2];
>   char d;
> };
> 
>   struct b ak = {0, 0}, am;
>   ae = &ad;
>   am = ak; // am = {};
>   af = &am.c; //&am.c
>   ac = *af + 1; //&am.c[1]
>   *ae = ac + 1; //ad = &am.c[2]
>   ag = *ad; // am.c[2]
>   return ag;
> 
> So reading the padding bits.
> So undefined code.

Interesting, this was missed by both GCC and Clang's UB sanitizer at -O0, but
it's at -O1 by GCC's: 

[535] % clangtk -O0 -fsanitize=undefined small.c; ./a.out
[536] % clangtk -O1 -fsanitize=undefined small.c; ./a.out
[537] % gcctk -O0 -fsanitize=undefined small.c; ./a.out
[538] % gcctk -O1 -fsanitize=undefined small.c; ./a.out
small.c:13:8: runtime error: index 3045496 out of bounds for type 'int [6]'
small.c:13:8: runtime error: load of address 0x7ffc8727daf0 with insufficient
space for an object of type 'int'
0x7ffc8727daf0: note: pointer points here
<memory cannot be printed>
Segmentation fault


The UB might be introduced by reduction, and I'm re-reducing it.

Reply via email to