<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><span class="vcard"><a class="email" href="mailto:vincent-llvm@vinc17.net" title="Vincent Lefevre <vincent-llvm@vinc17.net>"> <span class="fn">Vincent Lefevre</span></a>
</span> changed
<a class="bz_bug_link
bz_status_REOPENED "
title="REOPENED - incorrect optimization with signaling NaN and implicit conversion in fabs: missing exception"
href="https://bugs.llvm.org/show_bug.cgi?id=39112">bug 39112</a>
<br>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>What</th>
<th>Removed</th>
<th>Added</th>
</tr>
<tr>
<td style="text-align:right;">Status</td>
<td>RESOLVED
</td>
<td>REOPENED
</td>
</tr>
<tr>
<td style="text-align:right;">Resolution</td>
<td>DUPLICATE
</td>
<td>---
</td>
</tr></table>
<p>
<div>
<b><a class="bz_bug_link
bz_status_REOPENED "
title="REOPENED - incorrect optimization with signaling NaN and implicit conversion in fabs: missing exception"
href="https://bugs.llvm.org/show_bug.cgi?id=39112#c3">Comment # 3</a>
on <a class="bz_bug_link
bz_status_REOPENED "
title="REOPENED - incorrect optimization with signaling NaN and implicit conversion in fabs: missing exception"
href="https://bugs.llvm.org/show_bug.cgi?id=39112">bug 39112</a>
from <span class="vcard"><a class="email" href="mailto:vincent-llvm@vinc17.net" title="Vincent Lefevre <vincent-llvm@vinc17.net>"> <span class="fn">Vincent Lefevre</span></a>
</span></b>
<pre>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)</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>