https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110011
Bug ID: 110011
Summary: -mfull-toc yields incorrect _Float128 constants on
power9
Product: gcc
Version: 8.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: vincent-gcc at vinc17 dot net
Target Milestone: ---
Note: I selected version 8.3.1, because this is what I had for my tests, but at
least 13.1.0 is still affected (see below).
We got a report of a GNU MPFR failure on an IBM POWER9 machine:
https://sympa.inria.fr/sympa/arc/mpfr/2023-05/msg00000.html
With additional information given in a private discussion, Matthew R. Wilson
found that the failure came from the use of -mfull-toc in CFLAGS (this is not
visible in the report mentioned above), and he could reproduce the behavior
with GCC 13.1.0, 12.2.0, as well as the Debian-provided GCC 10.2.1. As he
noticed, -mfull-toc is documented to be the default, so that this shouldn't
have any effect.
I could reproduce the failure on gcc135 at the Compile Farm with
/opt/at12.0/bin/gcc
(gcc (GCC) 8.3.1 20190304 (Advance-Toolchain-at12.0) [revision 269374]), and I
did some tests with it.
It appears that when -mfull-toc is provided, the cause is incorrect _Float128
constants MPFR_FLOAT128_MAX and -MPFR_FLOAT128_MAX, where one has
#define MPFR_FLOAT128_MAX 0x1.ffffffffffffffffffffffffffffp+16383f128
Indeed, I added
_Float128 m = MPFR_FLOAT128_MAX, n = -MPFR_FLOAT128_MAX;
at the beginning of the mpfr_set_float128 function in src/set_float128.c, and
did the following:
1. Compile MPFR (and the testsuite) using
CFLAGS="-mcpu=power9 -O0 -g -mfull-toc"
2. In the "tests" directory, gdb ./tset_float128
3. Add a breakpoint on mpfr_set_float128, then run, next, and print values:
(gdb) print m
$1 = 5.96937875341074040910051755689516189e-4947
(gdb) print n
$2 = 1.19416736664469867978830578385372193e-4946
Both are wrong.
If I do the same test with CFLAGS="-mcpu=power9 -O0 -g" (i.e. without
-mfull-toc), then I get
(gdb) print m
$1 = 1.18973149535723176508575932662800702e+4932
(gdb) print n
$2 = -1.18973149535723176508575932662800702e+4932
These are the expected values.
Unfortunately, I couldn't reproduce the issue with a simple C program.