http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58685
Bug ID: 58685 Summary: wrong code at -Os on x86_64-linux-gnu in 64-bit mode (affecting gcc trunk, 4.8, and 4.7) Product: gcc Version: 4.9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: su at cs dot ucdavis.edu The current gcc trunk (as well as 4.7 and 4.8) miscompiles the following code on x86_64-linux at -Os in 64-bit mode. This is a regression from 4.6.x. $ 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 20131010 (experimental) [trunk revision 203390] (GCC) $ $ gcc-trunk -m64 -O1 small.c; a.out $ gcc-trunk -m64 -O2 small.c; a.out $ gcc-trunk -m32 -Os small.c; a.out $ gcc-4.6 -m64 -Os small.c; a.out $ $ gcc-trunk -m64 -Os small.c; a.out a.out: :1564818584: H?l$?L?d$?H?-? : Assertion `' failed. Aborted (core dumped) $ gcc-4.8 -m64 -Os small.c; a.out a.out: :2138443464: H?l$?L?d$?H?-? : Assertion `' failed. Aborted (core dumped) $ gcc-4.7 -m64 -Os small.c; a.out a.out: :1796453480: H?l$?L?d$?H?-? : Assertion `' failed. Aborted (core dumped) $ --------------------------------- int a, b, c = 1, d, e; int *f = &e, *g = &e, *i; void __assert_fail (char *); void fn1 () { if (a) i = 0; } int fn2 () { 0 ? (void) 0 : __assert_fail (""); for (; d;) ; return 0; } int fn3 (int *p1) { for (b = 0; b >= 0; b--) { int *h = &e; *h = 0; if (*p1) continue; e = 1; } fn1 (); c ? (void) 0 : __assert_fail (""); return 0; } int main () { fn3 (g); fn3 (g); if (*f); else 0 ? (void) 0 : __assert_fail (""); return 0; }