[PATCH] D157072: [clang][ExprConst] Check float operation input for signaling NaNs

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 4 11:14:17 PDT 2023


sepavloff added inline comments.


================
Comment at: clang/test/CXX/expr/expr.const/p2-0x.cpp:281-283
+    constexpr float f10 = f2 - f2;
+    constexpr float f11 = f2 + f4;
+    constexpr float f12 = f2 / f2;
----------------
I don't think silent NaN origination is a right behavior. By design NaN is used to represent errors, so if a NaN appears, it may indicate a situation that needs user's attention. NaN propagation should be silent, an error has already appeared somewhere in the code.

I don't think it should be an error either. A user can use NaN to mark an error and treat it as if it were created by hardware. The code like:
```
    const double PosNan = 1.0 / 0.0;
    const double NegNaN = -1.0 /0.0;
    const double NaN = 0.0 / 0.0;
```
is used enough often and there is no reason to prohibit it even in constant evaluations. So the best reaction could be a warning. Some users may suppress it, some promote to error.

This applies to other FP exceptions as well, but they were implemented previously.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157072/new/

https://reviews.llvm.org/D157072



More information about the cfe-commits mailing list