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

"zhendong.su at inf dot ethz.ch via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126937

            Bug ID: 126937
           Summary: wrong code at -O{s,2,3} 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/x4bv6qjGh

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

[574] % 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/17.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++,lto --disable-werror
--disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 17.0.0 20260819 (experimental) (GCC) 
[575] % 
[575] % gcctk -O1 small.c; ./a.out
[576] % 
[576] % gcctk -O2 small.c
[577] % ./a.out
Segmentation fault
[578] % 
[578] % cat small.c
int *a, b, d;
short c;
int main() {
  int f;
 L:
  b = ~(65535 << d);
  c = b ^ 1;
  if (c > b) {
    f = 0;
    if (c) {
      f = b;
      d = (b / c) && c;
      if (!b)
        goto L;
    }
    if (f >= 0)
      *a = 0;
  }
  return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.