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

            Bug ID: 82291
           Summary: wrong code at -O3 on x86_64-linux-gnu
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: su at cs dot ucdavis.edu
  Target Milestone: ---

It should be a recent regression as 7.2.0 does not miscompile the test. 

$ gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/home/su/software/tmp/gcc/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/8.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto
--prefix=/home/su/software/tmp/gcc/gcc-trunk --disable-bootstrap
Thread model: posix
gcc version 8.0.0 20170921 (experimental) [trunk revision 253084] (GCC)
$
$ gcc-7.2.0 -O3 small.c; ./a.out
0
$ gcctk -O2 small.c; ./a.out
0
$
$ gcctk -O3 small.c
$ ./a.out
1
$


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


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

int a, c, d, *h;
unsigned b;

int *fn1 ()
{ 
  int *f[3], g = 0;
  for (; g < 3; g++)
    f[g] = &a;
  if (--b > a)
    { 
      if (a > b)
        d++;
      return f[0];
    }
}

void fn2 ()
{ 
  for (; c >= 0; --c)
    { 
      int j[] = { 0, 0, 0, 0, 0 };
      int *k = fn1 ();
      if (!k)
        __builtin_abort ();
      h = &j[4];
    }
}

int main ()
{ 
  fn2 ();
  printf ("%d\n", d);
  return 0;
}

Reply via email to