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

            Bug ID: 121730
           Summary: wrong code at -O1 on x86_64-linux-gnu (generated code
                    hangs)
           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/1dYdar68f

Note:
- works: 10.5 and earlier
- fails: 11.1 and later
- -fno-tree-slsr and -fno-ivopts do not make it disappear
- only fails at -O1

[676] % 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 20250830 (experimental) (GCC)
[677] %
[677] % gcctk -O0 small.c; ./a.out
[678] %
[678] % gcctk -O1 small.c
[679] % timeout -s 9 5 ./a.out
Killed
[680] % gcctk -O1 -fno-tree-slsr -fno-ivopts small.c
[681] % timeout -s 9 5 ./a.out
Killed
[682] % cat small.c
volatile int a;
int b, c, d, e;
int f(int ab) {
  d = 94967295 ^ ab;
  e = (d & 2) ^ 4294967295 % 2147483647;
  return e;
}
static int g(volatile int h) {
  volatile int i = 3 / h;
  a = 1 - i;
  return 0;
}
static int j(volatile int k) {
  g(-2);
  if (b)
    c = 0;
  k = g(-2) + 1 % k - 1;
  return f(k);
}
int main() {
  while (j(2) < 2)
    ;
  return 0;
}

Reply via email to