[Bug tree-optimization/126637] New: wrong code at -O{s,2,3} with -fwhole-program on x86_64-linux-gnu

"zhendong.su at inf dot ethz.ch via Gcc-bugs" <[email protected]> Tue, 04 Aug 2026 11:51:52 +0000
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D126637

            Bug ID: 126637
           Summary: wrong code at -O{s,2,3} with -fwhole-program on
                    x86_64-linux-gnu
           Product: gcc
           Version: 16.0
            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/zoErbs1W1

Note:
- fails: trunk
- works: 16.1 and earlier

[574] % gcctk -v
Using built-in specs.
COLLECT_GCC=3Dgcctk
COLLECT_LTO_WRAPPER=3D/local/home/suz/suz-local/software/local/gcc-trunk/bi=
n/../libexec/gcc/x86_64-pc-linux-gnu/17.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk/configure --disable-bootstrap
--enable-checking=3Dyes --prefix=3D/local/suz-local/software/local/gcc-trunk
--enable-sanitizers --enable-languages=3Dc,c++,lto --disable-werror
--disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 17.0.0 20260804 (experimental) [master r17-1628-gd1c12591336] (=
GCC)=20
[575] %=20
[575] % gcctk -O3 small.c; ./a.out
[576] %=20
[576] % gcctk -O3 -fwhole-program small.c
[577] % timeout -s 9 5 ./a.out
Killed
[578] % cat small.c
double *a;
void b(int c) {
  int d =3D 1;
  double e =3D 1.0;
  a =3D &e;
  while (1) {
  if (!(e ? e : 4.0 < -c))
    break;
  e =3D d - 1;
  *a =3D -e;
  d =3D 2;
}
}
int main() { b(0); }=