https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127377
Bug ID: 127377
Summary: Wrong code at -O3 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/ncMvhTnqM
$ 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 CC='ccache
clang' CXX='ccache clang++' --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 20260913 (experimental) (GCC)
$
$ gcc-trunk -O0 small.c && ./a.out
$ gcc-trunk -O3 small.c && ./a.out
[1] 1299083 segmentation fault (core dumped) ./a.out
$
$ cat small.c
char e[] = {80};
int f, a, b, c;
char g;
long d[5];
long q(short r, char *s, long t, char *u, long w) {
struct h {
unsigned i : 1;
int : 1;
unsigned j : 3;
int k : 7;
int : 3;
int aa : 6;
unsigned l : 7;
};
union {
int m;
char b[4];
struct h ab;
} n;
long o = 955;
int p = w ^ 15876 & 2047 | 16;
n.m = w ^ 21860;
for (; p;) {
n.b[2] = n.ab.i + n.ab.aa;
o ^= n.ab.j;
n.m = n.m & ~28u | ((p >> 4 ^ n.ab.aa) & 7) << 2;
p >>= n.ab.j & 3;
}
n.b[3] = 0;
n.m = n.m | 3 << 6 << 21;
n.b[2] = w;
o = o * 3 + n.ab.i;
o = o * 3 + n.ab.j;
o = o * 3 + n.ab.k;
o = o * 3 + n.ab.aa;
o = o * 3 + n.ab.l;
o = o * 3;
o ^= w ^= r ^= t += u[15] += s[0];
return o;
}
int x(short r, long s, long t) {
char v[] = {5, 6, 6, 6, 1, 0, 8, 8, 3, 8, 0, 4, 7, 5, 8, 128};
return q(r, e, s, v, t);
}
long y(long *r) {
g = 296;
while (a++ < 5)
;
while (x(g + 8329, 5 - 11, g + 67) + a + g + 5 - -691462 + b < 7) {
b++;
c++;
}
f = -147 & 8191;
return r[f + b + c + 5 + g - 8113 + b];
}
void main() { y(d); }