http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58726
Bug ID: 58726 Summary: wrong code at -Os on x86_64-linux-gnu (affecting trunk/4.7/4.6, but not 4.8) Product: gcc Version: 4.8.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization Assignee: unassigned at gcc dot gnu.org Reporter: su at cs dot ucdavis.edu The current gcc trunk miscompiles the following code on x86_64-linux at -Os in both 32-bit and 64-bit modes. This is a regression from 4.8.x. It also affects 4.6.x and 4.7.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 20131014 (experimental) [trunk revision 203511] (GCC) $ $ gcc-trunk -O1 small.c; a.out -9162 $ gcc-trunk -Os small.c; a.out -32768 $ $ gcc-4.8 -Os small.c; a.out -9162 $ $ gcc-4.7 -Os small.c; a.out -32768 $ gcc-4.6 -Os small.c; a.out -32768 $ ------------------------------------ int printf (const char *, ...); int a, c; union { int f1; int f2:1; } b; short foo (short p) { return p < 0 ? p : a; } int main () { b.f1 = 56374; unsigned short d; int e = b.f2; d = e == 0 ? b.f1 : 0; c = foo (d); printf ("%d\n", c); return 0; }