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

            Bug ID: 68506
           Summary: wrong code at -O3 on x86_64-linux-gnu
           Product: gcc
           Version: 6.0
            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: ---

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

This is a regression from 5.2.x.

It is likely to do with VRP as -fno-tree-vrp seems to fix the miscompilation.

It also seems difficult to further reduce the code.  


$ 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 20151122 (experimental) [trunk revision 230719] (GCC)
$
$ gcc-trunk -O2 small.c; ./a.out
$ gcc-5.2 -O3 small.c; ./a.out
$ 
$ gcc-trunk -O3 -fno-tree-vrp small.c
$ ./a.out
$
$ gcc-trunk -O3 small.c
$ ./a.out
Segmentation fault (core dumped)
$


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


int a, b, m, n, o, p, s, u, i;
char c, q, y;
short d;
unsigned char e;
static int f, h;
static short g, r, v;
unsigned t;

void __assert_fail ();

int
fn1 (int p1)
{ 
  return a ? p1 : p1 + a;
}

unsigned char
fn2 (unsigned char p1, int p2)
{ 
  return p2 >= 2 ? p1 : p1 >> p2;
}

static short
fn3 ()
{ 
  int w, x = 0;
  for (; p < 31; p++)
    { 
      s = fn1 (c | ((1 && c) == c));
      t = fn2 (s, x);
      c = (unsigned) c > -(unsigned) ((o = (m = d = t) == p) <= 4UL) && n;
      v = -c;
      y = 1;
      for (; y; y++)
        e = v == 1;
      d = 0;
      for (; h != 2;)
        { 
          for (;;)
            { 
              if (!m)
                __assert_fail ();
              r = 7 - f;
              x = e = i | r;
              q = u * g;
              w = b == q;
              if (w)
                break;
            }
          break;
        }
    }
  return x;
}

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

Reply via email to