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

            Bug ID: 118900
           Summary: Wrong code at -O0 on x86_64-linux-gnu
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamanonymous.cs at gmail dot com
  Target Milestone: ---

Compiler Explorer: https://godbolt.org/z/cW8GGGWeo

*******************************************************************************
gcc version:
Using built-in specs.
COLLECT_GCC=/home/software/gcc-trunk/bin/gcc
COLLECT_LTO_WRAPPER=/home/software/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/15.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --disable-bootstrap --enable-checking=yes
--prefix=/home/software/gcc-trunk --enable-sanitizers --enable-languages=c,c++
--disable-werror --enable-multilib --enable-coverage
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 15.0.1 20250215 (experimental) (GCC)

*******************************************************************************
Program:
$ cat mutant.c
int printf(const char *, ...);
int a, c = 1;
int b[2];
int main() {
d:
  for (; a < 8; (a = (a + a - b[0]) + ((1 + (!!(c ^ c))) | (1 + (!!(c ^ c))))))
{
    int *e = &c;
    if ((((&b[1] - (a & ~a)) - a) == ((e + (!!(b[0] ^ b[0]))) - b[1])))
      *e = 0;
  }
f:
  if (0) {
    goto f;
    goto d;
  }
  printf("%d\n", c);
}

*******************************************************************************
Command Lines:
$ gcc -O0 mutant.c -o a.out && ./a.out
0
$ gcc -O1 mutant.c -o a.out && ./a.out
1
$ gcc -O0 -fsanitize=undefined,address mutant.c -o a.out && ./a.out
1
$ clang -O0 mutant.c -o a.out && ./a.out
1

Reply via email to