https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120046
Bug ID: 120046 Summary: wrong code at -O{s,2} with "-fno-tree-ccp -fno-tree-dominator-opts -fno-tree-fre -fno-expensive-optimizations -fno-gcse" 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: --- Compiler Explorer: https://godbolt.org/z/4hsdEKM4v It appears to be a recent regression, and affects 15.1 and later. [553] % 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/16.0.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ../gcc-trunk/configure --disable-bootstrap --enable-checking=yes --prefix=/local/suz-local/software/local/gcc-trunk --enable-sanitizers --enable-languages=c,c++ --disable-werror --enable-multilib Thread model: posix Supported LTO compression algorithms: zlib gcc version 16.0.0 20250430 (experimental) (GCC) [554] % [554] % gcctk -O2 small.c; ./a.out 0 [555] % gcctk -O2 -fno-tree-ccp -fno-tree-dominator-opts -fno-tree-fre -fno-expensive-optimizations -fno-gcse small.c [556] % ./a.out 0 Aborted [557] % [557] % cat small.c int printf(const char *, ...); struct a { long b; } d, g, *f = &d; int c, h; volatile int e; struct a i() { struct a j = {5000000000}, *k = &j; printf("0\n"); l: if (j.b) return j; if (h) { if (c) goto l; return g; } printf("%d", e); struct a *m, **n = &m; *n = k; return *m; } int main() { *f = i(); if (d.b != 5000000000) __builtin_abort(); return 0; }