https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110129
Bug ID: 110129 Summary: Possible wrong-code on -O2 and above (affecting versions from GCC-10.1 onward) Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: haoxintu at gmail dot com Target Milestone: --- Hi, Please consider the following code, which makes GCC output different results on -O0/1 and -O2/3/s. Note that all the GCC-10.1 (including) onwards versions behave the same. $cat test.c #include <stdio.h> int c = 0; int ids = 0; struct { int a; } b; void __attribute__((noinline)) marker_1() { printf(" b%db ", 1); ids++; } int d(int e) { b.a = 0; for (e = 0; e < 8; e++) for (c = 0; c < 9; c++) if (c){ for (; e; ) ; } return b.a; } int main() { int f[1] = {0}; if (d(c), f) marker_1(); printf("%d\n", ids); } $gcc-trunk -w -O1 test.c ;./a.out (hang) $gcc-trunk -w -O2 test.c ;./a.out b1b 1 $gcc-10.1 -w -O1 test.c ;./a.out (hang) $gcc-10.1 -w -O2 test.c ;./a.out b1b 1 $gcc-9.5 -w -O1 test.c ;./a.out (hang) $gcc-9.5 -w -O2 test.c ;./a.out b1b 1 GCC version: Using built-in specs. COLLECT_GCC=/opt/compiler-explorer/gcc-snapshot/bin/g++ COLLECT_LTO_WRAPPER=/opt/compiler-explorer/gcc-trunk-20230605/bin/../libexec/gcc/x86_64-linux-gnu/14.0.0/lto-wrapper Target: x86_64-linux-gnu Configured with: ../gcc-trunk-20230605/configure --prefix=/opt/compiler-explorer/gcc-build/staging --enable-libstdcxx-backtrace=yes --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --disable-bootstrap --enable-multiarch --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --enable-clocale=gnu --enable-languages=c,c++,fortran,ada,objc,obj-c++,go,d,rust,m2 --enable-ld=yes --enable-gold=yes --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-linker-build-id --enable-lto --enable-plugins --enable-threads=posix --with-pkgversion=Compiler-Explorer-Build-gcc-b48890844d94092fdf6e9c941af4a47b9c0ce982-binutils-2.40 Thread model: posix Supported LTO compression algorithms: zlib gcc version 14.0.0 20230605 (experimental) (Compiler-Explorer-Build-gcc-b48890844d94092fdf6e9c941af4a47b9c0ce982-binutils-2.40) Example in GodBolt: https://godbolt.org/z/3YhczK7oj Thanks, Haoxin