https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117367
Bug ID: 117367 Summary: Miscompile with different optimization flags Product: gcc Version: 14.1.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: --- Created attachment 59499 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59499&action=edit The preprocessed file When I compiled this code with O2 and O3 flags, its outputs were different: #define a() 0 #include <stdint.h> #include <stdio.h> char c[]; char *d; int32_t e; uint32_t f[]; const int32_t *i; int b() {} int v(int n, char *o) { char *g = o; d = c; while (n) { d++; n /= 10; } while (d != c) *g++ = *--d; *g++ = '\0'; return g - o - 1; } int h(int n, char) { char p[3]; int l = v(n, p); return l; } void m() {} const int32_t *q(); uint16_t r() { int16_t s[1][3][2]; int32_t *t = &e, j, k; for (; j < 3; j++) for (k = 0; k < 2; k++) s[h(53, 0) - 2][j][k] = 1; if ((*t = b() - 1 + s[0][0][1]) != m) ; else for (;;) if (*i) if (f[a()]) { const int32_t **u = &i; *u = q(); } } const int32_t *q() {} int main() { r(); printf("%d\n", e); } For O2, its output is: 0 For O3, its output is: -1 The details can be found here: https://godbolt.org/z/334KGnj77