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

            Bug ID: 118623
           Summary: Miscompile with -O2/3 and -O0/1
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yunboni at smail dot nju.edu.cn
  Target Milestone: ---

This code prints 1 at -O2/3 and 0 at -O0/1:

```c
int printf(const char *, ...);
int a, b;
int c(int f, int g) {
  for (int d = 0; d <= 4; d++) {
    int e = 1 << f;
    if (g & e)
      return d;
  }
  return 5;
}
int h(int f, int g) {
  if ((c(g - 50, g) + g + g) & 1);
  else if (f)
      a = 1;
  printf("%d\n", a);
  return a;
}
int main() {
  h(b + 5, b + 63);
}
```

Compiler Explorer: https://godbolt.org/z/a8ds63o8G

It starts with gcc 12.1.

Reply via email to