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

            Bug ID: 103399
           Summary: [12 Regression] Wrong code with -O2
           Product: gcc
           Version: 12.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: ---

Link to the Compiler Explorer: https://godbolt.org/z/3GE6fKvYr

Reproducer:

#include <stdio.h>
char a = 0;
long long b[8][10][18];
void e(int, long long[][10][18]) __attribute__((noipa));
void e(int f, long long g[][10][18]) {
  for (int d = 0; d < f; d += 3LL)
    for (int c = 0; c < ((f ? g[5][0][0] : 0) ^ g[5][0][0]) + 1; c++)
      a = 42;
}
int main() {
  for (size_t i = 0; i < 8; ++i)
    for (size_t k = 0; k < 10; ++k)
      for (size_t j = 0; j < 8; ++j)
        b[i][k][j] = -1311387439415292401LL;
  e(8, b);
  printf("%u\n", a);
  if (a != 42)
    __builtin_abort();
}

Error:
>$ g++ -O1 driver.cpp && ./a.out
42
>$ g++ -O2 driver.cpp && ./a.out
0

gcc version 12.0.0 20211123 (721d8b9e26bf8205c1f2125c2626919a408cdbe4) (GCC)

Reply via email to