http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58677
Bug ID: 58677 Summary: wrong code at -O1 on x86_64-linux-gnu Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: su at cs dot ucdavis.edu The current gcc trunk miscompiles the attached testcase on x86_64-linux at (only) -O1 in 64-bit mode. This is a regression from 4.8.x. This one was quite tough to reduce. The attached testcase is the best I was able to get so far. $ gcc-trunk -v Using built-in specs. COLLECT_GCC=gcc-trunk COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-unknown-linux-gnu/4.9.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../gcc-trunk/configure --enable-languages=c,c++,objc,obj-c++,fortran,lto --disable-werror --enable-checking=release --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 20131009 (experimental) [trunk revision 203302] (GCC) $ $ gcc-trunk -O0 small.c; a.out 0 0 1 $ gcc-4.8 -O1 small.c; a.out 0 0 1 $ gcc-trunk -m32 -O1 small.c; a.out 0 0 1 $ clang-trunk -O1 small.c; a.out 0 0 1 $ gcc-trunk -O1 small.c; a.out 0 0 0 $ ------------------------------------- int printf (const char *, ...); #pragma pack(1) struct S { unsigned int f0:7; int f1:19; unsigned int f2:22; int f3:25; } k[6][8]; int a, b, c, e, h, l, m, n, o, *p = &h, **q = &p, r, s; unsigned int d[256]; static void fn1 () { for (a = 0; a < 256; a++) d[a] = a; } static void fn2 (unsigned int p1, char *p2, int p3) { e = d[e ^ p1]; printf ("%s%X\n", p2, e); } static int * fn3 (int p1, int p2) { for (s = 10; s > 2; s = -6) for (r = 0; r < 6; r++) for (n = 0; n < 8; n++) { struct S t = { 1, -195, 321, 4857 }; k[r][n] = t; } return *q; } static int fn4 () { *q = fn3 (l, b); return c; } int main (int argc, char *argv[]) { int v = 0; if (argc == 2) v = 1; fn1 (); fn4 (); fn2 (m, "", v); fn2 (o, "", v); fn2 (k[0][0].f0, "", v); return 0; }