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

            Bug ID: 69377
           Summary: wrong code at -O2 on x86_64-linux-gnu (in 32-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 miscompiles the following code on x86_64-linux-gnu at -O2
in the 32-bit mode (but not in the 64-bit mode). 

This is a regression from 5.3.x. 

The reduced test is still fairly large; this has been a tough one to reduce. 


$ 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 20160119 (experimental) [trunk revision 232571] (GCC) 
$ 
$ gcc-trunk -m32 -Os small.c; ./a.out
2
1
1
$ gcc-5.3 -m32 -O2 small.c; ./a.out
2
1
1
$ gcc-trunk -m32 -O2 small.c
$ ./a.out
2
1
$ 



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



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

int r, *s, t, p, a, q, b;
short u = 3;
static int *v;
char c;

static int *
fn1 (int p1)
{
  int w = 2, j;
  for (; q < 1;)
    {
      int d = 6094 ^ p, e = ~r;
      p = e;
      if (!d)
        return &t;
      j = 0;
      for (; j < 1;)
        {
          j = 0;
          for (; j < 1; j++)
            for (; q < 2; q++)
              ;
        }
    }
  if (u)
    for (;;)
      {
        char x;
        int y, z = 1, t1;
        x = 7;
        for (; x; x++)
          {
            int f = p || r;
            t1 = ~p | w;
            w = (u || f % a) % ~(t1 && f) - r;
            if (p < 6)
              {
                printf ("%d\n", t1);
                break;
              }
          }
        int g = 4 % w;
        if (g)
          {
            --p;
            int h = p && t1;
            z = h;
            if (p > 5 && z)
              continue;
          }
        y = g;
        if (z < p)
          {
            int i = g / u;
            y = i;
          }
        int j = u & y, k, o = z * x;
        if (p)
          {
            k = z;
            o = t1;
            c = x;
            z = -y;
            t1 = (j && y << c) + k || x;
            x = ~(u % p);
            if (x < c)
              printf ("%d\n", t1);
          }
        int l = p < z;
        short m = ((l && y) & ~u) * t1;
        int n = u && t1;
        if (t1 && x && (!x || z))
          m = l * (y && n) | x;
        printf ("%d\n", t1);
        if (o && m > w)
          *v = 0;
        else
          {
            if (!p1)
              continue;
            return &b;
          }
      }
}

static void
fn2 (char p1)
{
  s = fn1 (254);
  for (; p1 <= 0;)
    {
      s = fn1 (254);
      for (;;)
        ;
    }
}

int
main ()
{
  fn2 (4);
  return 0;
}

Reply via email to