[llvm] [clang-tools-extra] [clang] [CLANG] Add warning when INF or NAN are used in a binary operation or as function argument in fast math mode. (PR #76873)
Zahira Ammarguellat via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 15 09:05:34 PST 2024
================
@@ -13861,6 +13897,36 @@ Sema::CheckReturnValExpr(Expr *RetValExp, QualType lhsType,
CheckPPCMMAType(RetValExp->getType(), ReturnLoc);
}
+/// Diagnose comparison to NAN or INFINITY in fast math modes.
+/// The comparison to NaN or INFINITY is always false in
+/// fast modes: float evaluation will not result in inf or nan.
+void Sema::CheckInfNaNFloatComparison(SourceLocation Loc, Expr *LHS, Expr *RHS,
----------------
zahiraam wrote:
I have actually tried that but I noticed that `getSpellingOfSingleCharacterNumericConstant` of inf/nan will both return "0" so I will have no way to distinguish between inf + 1 and 0 + 1 and both will generate a warning. Unless there is other way of finding out that the token is nan/inf?
https://github.com/llvm/llvm-project/pull/76873
More information about the cfe-commits
mailing list