https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126658
Bug ID: 126658
Summary: Wrong code at -O1 on x86_64-pc-linux-gnu
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: xintong.zhou1 at uwaterloo dot ca
Target Milestone: ---
Compiler Explorer: https://godbolt.org/z/G7E37EjdY
$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=/data/x27zhou/compiler-nightly/install/gcc/bin/gcc
COLLECT_LTO_WRAPPER=/data/x27zhou/compiler-nightly/install/gcc/libexec/gcc/x86_64-pc-linux-gnu/17.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /data/x27zhou/compiler-nightly/src/gcc/configure
--enable-checking=yes --disable-bootstrap --disable-multilib
--enable-languages=c,c++ --prefix=/data/x27zhou/compiler-nightly/install/gcc
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 17.0.0 20260801 (experimental) (GCC)
$
$ gcc-trunk -O0 small.c && ./a.out
3
$ gcc-trunk -O1 small.c && ./a.out
0
$
$ cat small.c
#include <stdio.h>
long a, b;
int c, d;
long long e[1];
char f(long long *p1, int i, long long *p3) {
long long *g;
for (; a < i; a++)
g = p1 + 1;
while (g != p1) {
--g;
b = g - p1;
if (p3[b])
c = 3;
}
return c;
}
int main() {
long long j[] = {1096435691};
d = f(e, 2147483647 - 2147279301, j);
printf("%d\n", d);
}
Bisected to
https://gcc.gnu.org/cgit/gcc/commit/?id=c209c1598da631e0303e6db9556c80b587d61992