https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117841
Bug ID: 117841
Summary: Miscompile with -O3 and -O0/1/2
Product: gcc
Version: 14.2.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 -O3, it triggered SIGSEGV. With -O0/1/2, its
output is 0:
int printf(const char *, ...);
int a, d, e;
char b[11];
char *c;
char f;
static short *h;
long j;
int m(int n, char *o) {
char *g = o;
c = b;
while (n)
*c++ = n /= 10;
while (c != b)
*g++ = *--c;
*g = '\0';
return g - o - 1;
}
int p(int n) {
char k[10];
int l = m(n, k);
return l;
}
int main() {
int *r[5];
int i = 0;
for (; p(15) + i < 5; i++)
r[i] = &d;
int q = *r[0];
for (; e;)
f = *h;
if (q)
j = 2;
printf("%X\n", a);
}
Compiler Explorer: https://godbolt.org/z/r4so7zrcq