diff options
author | Patrick Palka <ppalka@redhat.com> | 2021-09-24 12:36:26 -0400 |
---|---|---|
committer | Patrick Palka <ppalka@redhat.com> | 2021-09-24 12:36:26 -0400 |
commit | 34947d4e97ee72b26491cfe5ff4fa8258fadbe95 (patch) | |
tree | d9e40c8584fc2f9fe1bf22ff154e4eac8f497027 /gcc/fortran/expr.c | |
parent | 51ca05031959d3accffe873e87d4bc4fbd22e9e9 (diff) | |
download | gcc-34947d4e97ee72b26491cfe5ff4fa8258fadbe95.zip gcc-34947d4e97ee72b26491cfe5ff4fa8258fadbe95.tar.gz gcc-34947d4e97ee72b26491cfe5ff4fa8258fadbe95.tar.bz2 |
real: fix encoding of negative IEEE double/quad values [PR98216]
In encode_ieee_double/quad, the assignment
unsigned long WORD = r->sign << 31;
is intended to set the 31st bit of WORD whenever the sign bit is set.
But on LP64 hosts it also unintentionally sets the upper 32 bits of WORD,
because r->sign gets promoted from unsigned:1 to int and then the result
of the shift (equal to INT_MIN) gets sign extended from int to long.
In the C++ frontend, this bug causes incorrect mangling of negative
floating point values because the output of real_to_target called from
write_real_cst unexpectedly has the upper 32 bits of this word set,
which the caller doesn't mask out.
This patch fixes this by avoiding the unwanted sign extension. Note
that r0-53976 fixed the same bug in encode_ieee_single long ago.
PR c++/98216
PR c++/91292
gcc/ChangeLog:
* real.c (encode_ieee_double): Avoid unwanted sign extension.
(encode_ieee_quad): Likewise.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/nontype-float2.C: New test.
Diffstat (limited to 'gcc/fortran/expr.c')
0 files changed, 0 insertions, 0 deletions