[cfe-dev] signbit returns false for negative NaN

Philip Reames listmail at philipreames.com
Fri Jun 6 14:18:29 PDT 2014


On 06/06/2014 01:02 PM, Chandler Carruth wrote:
>
> On Fri, Jun 6, 2014 at 12:52 PM, Stephen Canon <scanon at apple.com 
> <mailto:scanon at apple.com>> wrote:
>
>     This appears to have nothing to do with signbit, but rather that
>     we are somehow "optimizing" --NaN ---> NaN.
>
>     int main(int argc, char *argv[]) {
>     double x = -__builtin_nan("");
>         printf("%d\t%d\n", signbit(x));
>     return0;
>     }
>
>     this prints zero on recent clang (should print 1).  Stepping
>     through, x is being set to a positive NaN.
>
>
> The standards for C and C++, and consequentially Clang and LLVM, are 
> terribly underspecified w.r.t. things like NaN behavior. =/ We have 
> seen this before, and even if we fix it in Clang/LLVM I worry that it 
> will regress as there are many places where we model NaNs in a manner 
> slightly too aggressive to be strictly IEEE-754 conforming. =[
Is being IEEE-754 conforming a worthwhile goal?  If so, we could talk 
about how to improve testing to prevent such regressions and find other 
latent bugs.

I would generally argue in favour of conformance, but am not familiar 
with exactly what the C/C++ rules are.

To say this differently, are there important optimizations we don't want 
to loose which aren't conforming?

Philip
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140606/2e398d87/attachment.html>


More information about the cfe-dev mailing list