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

            Bug ID: 117425
           Summary: Miscompile with different optimization flags
           Product: gcc
           Version: 4.7.3
            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: ---

When I compiled this code with -O1/2/3, its output would be 8. However, with
-O0, its output is 7: 

```c
int printf(const char *, ...);
int a;
long b = 1;
long *c = &b, *d = &b;
int e() {
  for (; *d + a <= 7; a++)
    ;
  return 0;
}
int main() {
  e() | ((*c = 0, 0) || 0);
  printf("%d\n", a);
  return 0;
}
```

The version is gcc 4.7.3. I've checked the code with -Wall and -Wextra. The
unused warning seems to have no influence on this miscompilation. When I assign
a varibale to e() | ((*c = 0, 0) || 0) and print the value, it's always 0 and
the value of a is still different.

The details can be found here: https://godbolt.org/z/eWPTW5E7c

Reply via email to