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

            Bug ID: 91240
           Summary: Wrong code with -O3
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vsevolod.livinskij at frtk dot ru
  Target Milestone: ---

GCC produces wrong code with -O3.

Reproducer:

#include <stdio.h>

long long a;
int b[96][76];
int c[81];

void d(long long *e, int p2) { *e ^= p2; }

int main() {
  for (int f = 0; f < 80; ++f)
    for (int g = 0; g < 76; ++g)
      b[f][g] = c[f] = 9094;

  for (int f = 6; f <= 9; f++)
    for (int g = 6; g <= 75; g++)
      if (b[0][g])
        c[f + 1] *= f + (unsigned)c[f];

  printf("%d\n", c[8]);
}

Error:
>$ gcc -O3 small.c ; ./a.out
1637288310
>$ gcc -O0 small.c ; ./a.out
-2106497818

GCC version is 10.0.0 (Rev: 273743)

Reply via email to