https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110141
Bug ID: 110141 Summary: Wrong code at -O2 on x86_64-linux-gnu Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: shaohua.li at inf dot ethz.ch Target Milestone: --- For the following code, gcc since 12 emits the wrong code at -O2. Compiler explorer: https://godbolt.org/z/reGo6jqGK $ cat a.c int printf(const char *, ...); int h, i = 1, m; int *j = &i, *k = &i, *l; short n(short b, short c, int d) { short e[] = {71, c, c, 40, 28, 57, 3, 8, 79, 19, c}; int f = d, a = b; short *g = e; while (f > 1) { a += *g++; f -= 2; } a += *g -= 255; return a; } int fn2() { h = 0; for (;; h = 5) { int o[4]; m = 0; for (; m < 4; m++) o[n(6, 7, 19) - 70 + m] = 6; if (h) { for (;;) { int p = 0; if (*k) break; l = &p; } *j = o[0]; return 0; } } } int main() { fn2(); printf("%d\n", i); } $ $ gcc-tk -O0 a.c && ./a.out 6 $ gcc-tk -O2 a.c && ./a.out 0 $