https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68298

            Bug ID: 68298
           Summary: wrong code at -O3 on x86_64-linux-gnu (in 64-bit mode)
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu
  Target Milestone: ---

The current gcc trunk (as well as 5.1.x and 5.2.x) miscompiles the following
code on x86_64-linux-gnu at -O3 in the 64-bit mode (but not in the 32-bit
mode). 

This is a regression from 4.9.x. 


$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/usr/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/6.0.0/lto-wrapper
Target: x86_64-pc-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 6.0.0 20151110 (experimental) [trunk revision 230107] (GCC) 
$ 
$ gcc-trunk -m64 -O2 small.c; ./a.out
0
$ gcc-trunk -m32 -O3 small.c; ./a.out
0
$ gcc-4.9 -m64 -O3 small.c; ./a.out
0
$ 
$ gcc-trunk -m64 -O3 small.c
$ ./a.out
Segmentation fault (core dumped)
$ gcc-5.2 -m64 -O3 small.c
$ ./a.out
Segmentation fault (core dumped)
$ gcc-5.1 -m64 -O3 small.c
$ ./a.out
Segmentation fault (core dumped)
$ 


---------------------------------


int printf (const char *, ...); 

int a[1], b, c, d;
char e = 2;

char
fn1 ()
{
  if (e > 1)
    return e;
}

void
fn2 ()
{
  b = fn1 ();
  for (; c;)
    ;
  if (!e)
    b = a[400];
  printf ("0\n");
}

void
fn3 ()
{
  for (; d;)
    ;
  for (; d < 1; d++)
    fn2 ();
}

int
main ()
{
  fn3 ();
  return 0;
}

Reply via email to