[clang] [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
Wed Jan 10 06:10:08 PST 2024


================
@@ -6771,6 +6771,9 @@ 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<
+  "explicit comparison with %0 when the program is assumed to not use or produce %0">,
----------------
AaronBallman wrote:

```suggestion
  "explicit comparison with %select{infinity|NaN}0 will always return '%select{false|true}1' because %select{infinity|NaN}0 will not be produced according to the currently enabled floating-point options">,
```
How about something along these lines? I mostly want to replace the `%0` with a `select` so we don't have to pass in constant strings at the use sites, and I want to explicitly tell the user whether the comparison will always be true or always be false.

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


More information about the cfe-commits mailing list