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

            Bug ID: 71408
           Summary: wrong code at -Os and above on x86_64-linux-gnu
           Product: gcc
           Version: 7.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 -Os
and above in both 32-bit and 64-bit modes.

This is a regression from 6.1.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/7.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-source-trunk/configure --enable-languages=c,c++,lto
--prefix=/usr/local/gcc-trunk --disable-bootstrap
Thread model: posix
gcc version 7.0.0 20160603 (experimental) [trunk revision 237075] (GCC) 
$ 
$ gcc-trunk -O1 small.c; ./a.out
$ gcc-6.1 -Os small.c; ./a.out
$ 
$ gcc-trunk -Os small.c
$ ./a.out
4
$ 


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


unsigned a, b;

struct S0
{
  int f1:18;
  unsigned f3:4;
};  

void fn1 ()
{
  struct S0 c = { 7, 0 };
  if (c.f1)
    c.f3 = 3;
  a = -~c.f3;
  c.f3 = ~(c.f1 && c.f1);
  c.f1 = c.f3 * (c.f1 - (c.f1 - a % c.f1)) + ~c.f3 * -a;
  b = ~(c.f1 & a);
  if (b >= 4294967295)
    __builtin_printf ("%d\n", a);
}

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

Reply via email to