[cfe-dev] Clang-Cl - Representation of NAN; Code to reproduce

Kaylor, Andrew via cfe-dev cfe-dev at lists.llvm.org
Tue Feb 5 11:57:09 PST 2019


In the first case (0.0/0.0) clang's constant folder gets rid of the division and replaces it with clang's default representation of NaN. In the second case (0.0/bla) because you've declared 'bla' as volatile we actually perform the division, so the NaN in that case comes from the processor.

-Andy

From: cfe-dev <cfe-dev-bounces at lists.llvm.org> On Behalf Of Gaier, Bjoern via cfe-dev
Sent: Tuesday, February 05, 2019 1:33 AM
To: cfe-dev at lists.llvm.org
Subject: [cfe-dev] Clang-Cl - Representation of NAN; Code to reproduce


I discovered something new, that is interesting:

When I compile:



volatile const double result = 0.0/0.0;

This will result in "0x7FF8000000000000"



But:

volatile const double bla      = 0.0;

volatile const double result = 0.0/bla;

Will result in "0xFFF8000000000000"



Both compiled with Clang of course!


From: cfe-dev <cfe-dev-bounces at lists.llvm.org<mailto:cfe-dev-bounces at lists.llvm.org>> On Behalf Of Gaier, Bjoern via cfe-dev
Sent: Dienstag, 5. Februar 2019 09:29
To: cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>
Subject: [cfe-dev] Clang-Cl - Representation of NAN

Hello everyone,

we are currently using clang-cl (build with LLVM7) in our project, which previously used the MSVC2017 compiler. We noticed a major difference with the representation of the NAN value.
Clang generates 0x7FF8000000000000 for an NAN
MSVC  generates 0xFFF8000000000000 for an NAN

This difference leads to problems with C#, because it interacts with our C++ code and 'misses' the NAN.

Is there a way to change the representation of the NAN via a compiler flag?
Could we also change the source code of clang to force this representation of NAL? Or is this to much effort for a workaround?

Kind greetings
Björn
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190205/7d0e6d03/attachment.html>


More information about the cfe-dev mailing list