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

            Bug ID: 114207
           Summary: Wrong code bug since GCC 12.1
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: congli at smail dot nju.edu.cn
  Target Milestone: ---

The program below shows a wrong code bug, where the correct result should be
"s.a=12, s.b=6" while `-w -O3 -fno-tree-forwprop` prints "s.a=12, s.b=0" or
"s.a=12, s.b=<random>". The bug stems from at least GCC 12.1 to our trunk.

```
#include <stdio.h>
#include <stdint.h>

struct S {
    int a, b;
};

__attribute__((noinline))
void foo (struct S *s) {
    struct S ss = (struct S) {
        .a = s->b,
        .b = s->a
    };
    *s = ss;
}

int main() {
  struct S s = {6, 12};
  foo(&s);
  printf("s.a=%d, s.b=%d\n", s.a, s.b);
  return 0;
}
```

Compiler Explorer: https://gcc.godbolt.org/z/8dbMWjsd8

After checking the assembly, we found that `8(%rsp)` (representing s.b) was not
initialized by the constant `6` while it is printed.

Reply via email to