http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57303
Bug ID: 57303 Summary: struct miscompiled at -O1 and above Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: dhazeghi at yahoo dot com With current gcc trunk, the code below is miscompiled at -O1 and higher optimization levels on x86_64-linux-gnu, outputting '1' instead of '0' as expected. This behavior appears in gcc 4.8.x and 4.7.x as well, but not in 4.6.x or earlier. It occurs in both 32-bit and 64-bit compiles. $ gcc-trunk -v Target: x86_64-unknown-linux-gnu Configured with: ../gcc-trunk/configure --enable-languages=c,c++,objc,obj-c++,fortran,lto --disable-checking --with-gmp=/usr/local/gcc-trunk --with-mpfr=/usr/local/gcc-trunk --with-mpc=/usr/local/gcc-trunk --with-cloog=/usr/local/gcc-trunk --prefix=/usr/local/gcc-trunk Thread model: posix gcc version 4.9.0 20130516 (experimental) [trunk revision 198967] (GCC) $ gcc-trunk -O0 small.c $ ./a.out 0 $ gcc-4.6 -O1 small.c $ ./a.out 0 $ gcc-trunk -O1 small.c $ ./a.out 1 $ ----------------------------- int printf(const char *, ...); struct S0 { int f0; }; struct S1 { struct S0 f0; }; struct S1 x = { {0} }; struct S1 y = { {1} }; static void foo (struct S0 p) { struct S0 *l = &y.f0; *l = x.f0; if (p.f0) *l = *l; } int main () { foo(y.f0); printf("%d\n", y.f0.f0); return 0; }