https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121992
Bug ID: 121992
Summary: wrong code at -O2 on x86_64-linux-gnu
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: iamanonymous.cs at gmail dot com
Target Milestone: ---
This code returns 0 at -O0/1/s/3 and 1 at -O2:
$cat case.c
```
int a, b, c, d;
int e(int f, int g) {
if (g & (b | c | a))
return 0;
switch (f) {
case 4:
return d;
default:
return 0;
}
}
typedef struct {
unsigned short h : 1;
unsigned short i : 1;
unsigned short j : 1;
unsigned short k : 1;
unsigned short l : 1;
unsigned short m : 1;
unsigned short n : 1;
unsigned short o : 1;
unsigned short q : 1;
unsigned short r : 1;
unsigned short s : 1;
unsigned short t : 1;
unsigned short u : 1;
} v;
v w = {0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1};
unsigned short *p = (unsigned short *)&w;
int main() {
w.h = 1;
return (short)(e(*p, 3) + *p - 4661) + *p == 4661 ? 0 : 1;
}
```
Compiler Explorer: https://godbolt.org/z/o6oPr4bTE