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

            Bug ID: 129302
           Summary: [14/15/16/17 Regression] wrong code at -O1
                    -fallow-store-data-races: a speculated bool load/store
                    of a union member is value-normalized and written
                    back, clobbering a never-written byte
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 0599jiangyc at gmail dot com
  Target Milestone: ---

The following code:

```c
#include <stdbool.h>
#include <stdio.h>
union U { bool b; long long t; };
union U s;
__attribute__((noipa)) void f (int c, int n) { for (int i = 0; i < n; i++) if
(c == i) s.b = 0; }
int main (void)
{
  s.t = -2;
  f (5, 3);
  printf ("%016llx\n", (unsigned long long) s.t);
  return s.t != -2;
}
```

Resulted in this output:
```
$ gcc -O0 -fallow-store-data-races repro.c && ./a.out
fffffffffffffffe
$ gcc -O2 -fallow-store-data-races repro.c && ./a.out
ffffffffffffff00
(also -O1 and -O3 with -fallow-store-data-races; -O2, and -O2
-fallow-store-data-races with -fno-tree-cselim or -fno-tree-loop-im exit 0)
```

Trunk: https://godbolt.org/z/5E89PrMGe
- Trunk, GCC 16.2, 15.2 and 14.2 abort; GCC 13.2 is OK.

Reply via email to