http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60404

            Bug ID: 60404
           Summary: wrong code by LTO on x86_64-linux-gnu
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu

The current gcc trunk miscompiles the following code when using LTO on
x86_64-linux-gnu in both 32-bit and 64-bit modes. 

This is a regression from 4.8.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 --prefix=/usr/local/gcc-trunk
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 4.9.0 20140303 (experimental) [trunk revision 208268] (GCC) 
$ 
$ gcc-trunk -flto -O1 -c fn1.c
$ gcc-trunk -flto -O1 -c fn2.c
$ gcc-trunk -flto -O1 -c main.c
$ gcc-trunk -flto -O0 fn1.o fn2.o main.o           
$ a.out
1
$ 
$ gcc-4.8.2 -flto -O1 -c fn1.c
$ gcc-4.8.2 -flto -O1 -c fn2.c
$ gcc-4.8.2 -flto -O1 -c main.c
$ gcc-4.8.2 -flto -O0 fn1.o fn2.o main.o
$ a.out
0
$ 
$ gcc-trunk -O0 fn1.c fn2.c main.c
$ a.out
0
$ 
$ cat fn1.c 
void
fn1 (int p)
{
}
$ cat fn2.c
extern int b;

extern void fn1 (int);

void
fn2 (int p)
{
  b = p++;
  fn1 (p);
}
$ cat main.c
int printf (const char *, ...);

extern void fn2 (int);

int a[1];
int b;

int
main ()
{
  fn2 (0);
  printf ("%d\n", a[b]);
  return 0;
}
$

Reply via email to