[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
Mon Jan 15 05:14:16 PST 2024
================
@@ -6784,6 +6784,12 @@ def warn_pointer_sub_null_ptr : Warning<
def warn_floatingpoint_eq : Warning<
"comparing floating point with == or != is unsafe">,
InGroup<DiagGroup<"float-equal">>, DefaultIgnore;
+def warn_fast_floatingpoint_eq : Warning<
+ "%select{explicit comparison with|use of}0 %select{infinity|nan}1 "
+ "%select{will always return 'false'|as a function argument will not always be interpreted as such}0 "
+ "because %select{infinity|nan}1 will not be produced according to the "
+ "currently enabled floating-point options">,
----------------
AaronBallman wrote:
Ah, now that I better understand the scope of the functionality, I think we should go with:
`use of %select{infinity|NaN}0 results in undefined behavior due to the currently enabled floating-point options`
and move the diagnostic out of the tautological compare warning group. You should also update ExprConstant.cpp to reject use of inf/nan in a constant expression with the options disabled.
https://github.com/llvm/llvm-project/pull/76873
More information about the cfe-commits
mailing list