https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117451
Bug ID: 117451
Summary: Miscompile with -00/1/2 and -O3
Product: gcc
Version: 15.0
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 O0/1/2 flag, its output is 94394. But with -O3,
it's 28858:
```c
int printf(const char *, ...);
char a;
int b, d, e, f;
char c[11];
int *l = &e;
int m(int p, char *p2) {
char *g, *h = p2;
if (p == 0)
;
else {
g = c;
while (p) {
*g++ = '0' + p % 10;
p /= 10;
}
while (g != c)
*h++ = *--g;
}
*h++ = '\0';
return h - p2 - 1;
}
int q(int p) {
char n[10];
int o = m(p, n);
return o;
}
int main() {
int i, j, k;
int r[3];
for (; q(15) + f < 3; f++)
r[f] = 94394;
for (; d <= 2; d++)
*l = r[0];
i = 0;
printf("%d\n", e);
for (; i < 3; i++) {
j = 0;
for (; j < 2; j++) {
k = 0;
for (; k < 4; k++)
if (b)
printf(&a);
}
j = 0;
for (; j < 8; j++)
if (b)
printf(&a);
}
}
```
Details can be found here: https://godbolt.org/z/8rvdq5osE