http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59162
Bug ID: 59162
Summary: wrong code (hangs) at -Os and above on
x86_64-linux-gnu (affecting 4.7.3 and earlier
versions)
Product: gcc
Version: 4.7.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: su at cs dot ucdavis.edu
GCC 4.7.3 and earlier versions miscompile the following code on x86_64-linux at
-Os and above in both 32-bit and 64-bit modes. But I did not check the latest
4.7 branch.
It affects neither the current trunk nor 4.8.x.
$ gcc-4.7.3 -O1 small.c; a.out
1
$ gcc-4.7.3 -Os small.c; a.out
^C
$ gcc-4.6.4 -Os small.c; a.out
^C
$ gcc-4.8.2 -Os small.c; a.out
1
$ gcc-trunk -Os small.c; a.out
1
$ 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
--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 20131117 (experimental) [trunk revision 204920] (GCC)
$
---------------------------------
int printf (const char *, ...);
int a, *b = &a;
int
main ()
{
short c = 0;
lbl:
++c;
*b |= 1;
if (c)
goto lbl;
printf ("%d\n", a);
return 0;
}