https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126856
Bug ID: 126856
Summary: [17 Regression] mpfr and mpc started failing tests
recently
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: slyfox at gcc dot gnu.org
Target Milestone: ---
Initially observed as mpfr test failure tset_d on mpfr-4.2.2 at
r17-3267-g7f549ea2b47a70, did not bisect. Extracted the example from
src/scale2.c
(https://gitlab.inria.fr/mpfr/mpfr/-/blob/4.2.2/src/scale2.c?ref_type=tags#L30)
as:
// $ cat bug.c
union mpfr_ieee_double_extract
{
struct
{
unsigned int manl:32;
unsigned int manh:20;
unsigned int exp:11;
unsigned int sig:1;
} s;
double d;
};
__attribute__((optimize(2)))
static double
mpfr_scale2_bad (double d, int exp)
{
union mpfr_ieee_double_extract x;
(! __builtin_constant_p (!!(-1073 <= exp && exp <= 1025) || !(-1073 <= exp
&& exp <= 1025)) || (-1073 <= exp && exp <= 1025) ? (void) 0 :
__builtin_unreachable());
x.d = d;
if (exp < -1021) __builtin_trap();
else x.s.exp += exp;
return x.d;
}
__attribute__((optimize(0)))
static double
mpfr_scale2_ok (double d, int exp)
{
union mpfr_ieee_double_extract x;
(! __builtin_constant_p (!!(-1073 <= exp && exp <= 1025) || !(-1073 <= exp
&& exp <= 1025)) || (-1073 <= exp && exp <= 1025) ? (void) 0 :
__builtin_unreachable());
x.d = d;
if (exp < -1021) __builtin_trap();
else x.s.exp += exp;
return x.d;
}
__attribute__((optimize(0)))
double
mpfr_scale2 (double d, int exp)
{
d = 1.0;
exp = 499;
double o = mpfr_scale2_ok(d, exp);
double b = mpfr_scale2_bad(d, exp);
if (o != b) {
__builtin_trap();
}
return b;
}
__attribute__((optimize(0)))
int main() {
mpfr_scale2(1,1);
}
Crashing:
$ gcc/xgcc -Bgcc /mnt/archive/big/git/mpfr/bug.c -o bug && ./bug
Illegal instruction (core dumped) ./bug
$ gcc/xgcc -Bgcc -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 17.0.0 20260813 (experimental) (GCC)