Open Quuxplusone opened 6 years ago
Bugzilla Link | PR39112 |
Status | REOPENED |
Importance | P normal |
Reported by | Vincent Lefevre (vincent-llvm@vinc17.net) |
Reported on | 2018-09-28 04:48:14 -0700 |
Last modified on | 2018-09-29 07:49:48 -0700 |
Version | trunk |
Hardware | PC Linux |
CC | efriedma@quicinc.com, hfinkel@anl.gov, llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also |
(In reply to Vincent Lefevre from comment #0)
> With a code that does something like
>
> float f = fabs (double_snan)
>
> one does not get the FE_INVALID exception with -O.
Oops, I meant:
float f = fabs (float_snan)
like in the details (I have not tried with double).
By default, clang assumes you don't access the floating-point environment. Work to implement the FENV_ACCESS pragma is ongoing.
_This bug has been marked as a duplicate of bug 8100_
No need to access the floating-point environment to reproduce the bug:
#include <stdio.h>
#include <inttypes.h>
#include <math.h>
typedef union { float f; uint32_t i; } ieee_float_t;
int main (void)
{
volatile ieee_float_t x, y;
x.i = 0x7f800001;
printf ("0. %x (%g)\n", x.i, x.f);
y.f = fabs (x.f);
printf ("2. %x (%g)\n", y.i, y.f);
return 0;
}
cventin% clang-8 snan.c -o snan -lm
cventin% ./snan
0. 7f800001 (nan)
2. 7fc00001 (nan)
cventin% clang-8 snan.c -o snan -lm -O
cventin% ./snan
0. 7f800001 (nan)
2. 7f800001 (nan)
With -O, one gets a signaling NaN instead of a quiet NaN.
The bug disappears if one explicitly uses a volatile double as an intermediate
variable (since fabs returns a double, this should not change anything):
#include <stdio.h>
#include <inttypes.h>
#include <math.h>
typedef union { float f; uint32_t i; } ieee_float_t;
int main (void)
{
volatile ieee_float_t x, y;
volatile double d;
x.i = 0x7f800001;
printf ("0. %x (%g)\n", x.i, x.f);
d = fabs (x.f);
y.f = d;
printf ("2. %x (%g)\n", y.i, y.f);
return 0;
}
cventin% clang-8 snan.c -o snan -lm
cventin% ./snan
0. 7f800001 (nan)
2. 7fc00001 (nan)
cventin% clang-8 snan.c -o snan -lm -O
cventin% ./snan
0. 7f800001 (nan)
2. 7fc00001 (nan)