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

            Bug ID: 123657
           Summary: wrong code at -O3
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jiangchangwu at smail dot nju.edu.cn
  Target Milestone: ---

This program prints 0 at -O0/1/2/s and prints 2 at -O3:

int printf(const char *, ...);
int a;
int main() {
  for (int b = 0; b < 21; b++) {
    int c = b;
    while (c)
      a = c >>= 1;
  }
  printf("%d\n", a);
}

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

Reply via email to