https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120661

            Bug ID: 120661
           Summary: compiler hang at -O{s,2,3} 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/ajPqMWGfo
- work: 15.1 and earlier
- fail: trunk at -O{s,2,3}

The code isn't valid due to reduction (but the unreduced test is).

[513] % gcctk -v
Using built-in specs.
COLLECT_GCC=gcctk
COLLECT_LTO_WRAPPER=/local/home/suz/suz-local/software/local/gcc-trunk/bin/../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 20250615 (experimental) (GCC) 
[514] % 
[514] % time gcctk -O1 small.c

real    0m0.088s
user    0m0.056s
sys     0m0.028s
[515] % 
[515] % timeout -s 9 60 gcctk -O3 small.c
Killed
[516] % cat small.c
#include <stdarg.h>
int a, c, d;
int e(int b, ...) {
    va_list args;
    va_start(args, b);
    int r = 0;
    for (int i = 0; i < b; i++) {
        int v = va_arg(args, int);
        r += v;
    }
    va_end(args);
    return r;
}
int f() { e(0); }
int main() {
  int h = 0, g = 0;
  goto l;
i:
  if (f() * h)
    goto k;
j:
  h = h - 2;
k:
  d = 1200000000 * h + 10;
  g = (long)g + -1000000000 * d + 1;
  if (a * h >= 0) {
    if (g + (c - (long)1) >= 0)
      goto i;
    return 0;
  }
l:
  goto j;
}

Reply via email to