https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97135
Bug ID: 97135 Summary: [11 Regression] Wrong code at -Os since r11-408-g84935c98221 Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: acoplan at gcc dot gnu.org Target Milestone: --- For the following testcase: long c; long *d = &c; int a, e, f; int main(void) { for (; f <= 5; f++) { e = 0; for (; e <= 5; e++) { a = 1; for (; a <= 5; a++); *d = 0; if (f) break; } } return a; } Compiling with -O{0,1,2,3} (for both gcc and clang), as expected, the program returns 6. Compiling with -Os, the program returns 1 (since r11-408-g84935c9822183ce403bb361c5f405711b9a808c6). I've reproduced this on both x86 and aarch64. Interestingly, compiling with -Os -fno-strict-aliasing, we no longer see the wrong code bug (the program returns 6). However, I believe this program is free of strict aliasing violations. To reproduce: $ bin/gcc wrong_code.c $ ./a.out || echo $? 6 $ bin/gcc wrong_code.c -Os $ ./a.out || echo $? 1 $ bin/gcc wrong_code.c -Os -fno-strict-aliasing $ ./a.out || echo $? 6