[clang] [CLANG] Add warning when INF or NAN are used in a binary operation or as function argument in fast math mode. (PR #76873)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 11 14:25:01 PST 2024


================
@@ -6771,6 +6771,11 @@ 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<
+  "use of %select{infinity|NaN}0 will always be 'false' because "
----------------
andykaylor wrote:

This doesn't make sense to me. What does it mean for a use to be false?

Maybe we're trying to wrap too much into a single diagnostic. For comparisons, the result of the comparison will be constant, so it makes sense to have a warning that tells the user what that constant result will be. However, when a constant NaN or infinity is passed as an argument to a function call, the situation is a bit more complicated. In that case, the optimizer can treat the input as poison. What effect that will have depends on the content of the called function. It might do nothing. It might cause the entire function call to be erased.

https://github.com/llvm/llvm-project/pull/76873


More information about the cfe-commits mailing list