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

            Bug ID: 110389
           Summary: wrong code at -Os and -O2 with "-fno-tree-ch
                    -fno-expensive-optimizations -fno-ivopts
                    -fno-tree-loop-ivcanon" 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: ---

It appears to be a regression from 11.*, and affects 12.* and later.

Compiler Explorer: https://godbolt.org/z/1nsvMbaPW


[567] % 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/14.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
--disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230623 (experimental) [master r14-924-gd709841ae0f] (GCC) 
[568] % 
[568] % gcctk -O2 -fno-tree-ch -fno-expensive-optimizations -fno-ivopts
-fno-tree-loop-ivcanon small.c
[569] % ./a.out
Segmentation fault
[570] % 
[570] % gcctk -O2 small.c; ./a.out
[571] % 
[571] % cat small.c
int a, b, c, d[3][1], e;
int main() {
  int f = 1, g;
  for (e = 0; e < 3; e++) {
    if (f)
      c--;
    for (g = 0; g < 1; g++) {
      if (b && a)
        return 0;
      f = 0;
      d[e][g] = 1;
    }
  }
  return 0;
}

Reply via email to