https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121572
Bug ID: 121572
Summary: [16 Regression] Wrong code on mpfr-4.2.2 and
python-3.13.6 since r16-3190-g5cf1b9a03ec5b6
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: slyfox at gcc dot gnu.org
Target Milestone: ---
I initially noticed the error as a python-3.13.6 build failure and a mpfr-4.2.2
testsuite failure. I bisected gcc down to r16-3190-g5cf1b9a03ec5b6 "x86-64:
Remove redundant TLS calls".
Out of mpfr-4.2.2 I managed to extract this self-contained example (needs 2
files):
// $ cat b.c
void bug(void);
int main(void) { bug(); }
// $ cat a.c
static __thread int tv_cache;
__attribute__((noipa)) static void use_cache (int) {}
__attribute__((noipa)) static int val (int v) { return v; }
__attribute__((noipa))
__attribute__((optimize(2)))
void bug (void)
{
int compared = val(-1);
if (compared == 0 || (compared > 0 && val(2) == 0))
{
__builtin_trap();
}
if (compared < 0) {
use_cache(tv_cache);
return;
}
use_cache(tv_cache);
__builtin_trap();
}
int main(void)
{
bug();
}
Crashing from a gcc build tree:
$ gcc="gcc/xgcc -Bgcc"; $gcc a.c -fPIC -shared -o liba.so && $gcc b.c -o b
-Wl,-rpath=. -L. -la && ./b
Illegal instruction (core dumped) ./b
It should work just fine. Minor tweaks (like -O1) usually make it work:
$ gcc="gcc/xgcc -Bgcc"; $gcc a.c -O1 -fPIC -shared -o liba.so && $gcc b.c -o b
-Wl,-rpath=. -L. -la && ./b
Compiler details:
$ gcc -v
Reading specs from gcc/specs
COLLECT_GCC=gcc/xgcc
COLLECT_LTO_WRAPPER=gcc/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /home/slyfox/dev/git/gcc/configure --disable-multilib
--disable-bootstrap --disable-lto --disable-libsanitizer --enable-languages=c
CFLAGS='-O1 -g0' CXXFLAGS='-O1 -g0' LDFLAGS='-O1 -g0'
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.0.0 20250816 (experimental) (GCC)