[clang] [clang-tools-extra] [llvm] [CLANG] Add warning when INF or NAN are used in a binary operation or as function argument in fast math mode. (PR #76873)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 18 14:48:01 PST 2024
================
@@ -2835,6 +2835,9 @@ class Preprocessor {
if (Identifier.getIdentifierInfo()->isRestrictExpansion() &&
!SourceMgr.isInMainFile(Identifier.getLocation()))
emitRestrictExpansionWarning(Identifier);
+
+ if (Identifier.getIdentifierInfo()->getName() == "INFINITY")
----------------
AaronBallman wrote:
We will?
```
#ifndef _HUGE_ENUF
#define _HUGE_ENUF 1e+300 // _HUGE_ENUF*_HUGE_ENUF must overflow
#endif
#define INFINITY ((float)(_HUGE_ENUF * _HUGE_ENUF))
...
#define NAN ((float)(INFINITY * 0.0F))
```
the multiplication for `INFINITY` won't form an actual infinity value in that case, so why would the multiplication with `0.0` not generate a NAN macro that folds to 0.0F?
If use of `INFINITY` is undefined behavior when `-fno-honor-infinities` is passed... it makes sense to me that the definition of `NAN` using `INFINITY` is UB by the same logic.
https://github.com/llvm/llvm-project/pull/76873
More information about the cfe-commits
mailing list