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

            Bug ID: 87022
           Summary: GCC miscompiles at -O3 on valid code
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: helloqirun at gmail dot com
  Target Milestone: ---

It also affects gcc-8.1 at -O3. gcc-7.3 works fine.

It appears that it starts at r253679.


$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/home/absozero/trunk/root-gcc/libexec/gcc/x86_64-pc-linux-gnu/9.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/home/absozero/trunk/root-gcc
--enable-languages=c,c++ --disable-werror --enable-multilib
Thread model: posix
gcc version 9.0.0 20180819 (experimental) [trunk revision 263651] (GCC)



$ gcc-trunk abc.c ; ./a.out > ref.txt
$ gcc-trunk -O3 abc.c ; ./a.out > a.txt
$ diff ref.txt a.txt
25,49c25,49
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
< 0
---
> 1
> 1
> 1
> 1
> 0
> 0
> 1
> 1
> 1
> 1
> 1
> 0
> 0
> 1
> 1
> 1
> 1
> 1
> 0
> 0
> 1
> 1
> 1
> 1
> 1
$ gcc-7.3 -O3 abc.c ; ./a.out > a.txt
$ diff ref.txt a.txt
$


$ cat abc.c
void printf();
char a[7];
char b[10][7];
short c;
int d, e, f, g;
int main() {
  for (; d <= 4; d++) {
    e = 0;
    for (; e <= 6; e++) {
      if (a[c])
        b[e + 3][d + 2] = 1;
      a[0] = 5;
      b[e][d + 2] = 0;
    }
  }
  for (; f < 10; f++) {
    g = 0;
    for (; g < 7; g++)
      printf("%d\n", b[f][g]);
  }
}

Reply via email to