https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106171
Bug ID: 106171 Summary: wrong code at -O1 and above on x86_64-linux-gnu Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: zhendong.su at inf dot ethz.ch Target Milestone: --- It appears to be quite long-latent, and affects all versions 7.* and later. [560] % gcctk -v Using built-in specs. COLLECT_GCC=gcctk COLLECT_LTO_WRAPPER=/local/suz-local/software/local/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/13.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-trunk/configure --disable-bootstrap --prefix=/local/suz-local/software/local/gcc-trunk --enable-sanitizers --enable-languages=c,c++ --disable-werror --enable-multilib --with-system-zlib Thread model: posix Supported LTO compression algorithms: zlib gcc version 13.0.0 20220703 (experimental) [master r13-1411-ga26f3eb2683] (GCC) [561] % [561] % gcctk -O0 small.c; ./a.out 1 [562] % gcctk -O1 small.c; ./a.out 0 [563] % gcctk -Os small.c; ./a.out -2089837456 [564] % gcctk -O2 small.c; ./a.out 0 [565] % gcctk -O3 small.c; ./a.out 0 [566] % [566] % cat small.c int printf(const char *, ...); int a, b; int c() { int d = 0; for (; d < 2; d++) { int e[2]; for (; b < 2; b++) e[b] = 1; if (d) return e[0]; } return 0; } int main() { a = c(); printf("%d\n", a); return 0; }