[clang] [NFC] Add assertion to ensure FiniteMathOnly is in sync with HonorINFs and HonorNANs. (PR #97342)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 3 11:48:17 PDT 2024


================
@@ -816,6 +816,11 @@ class FPOptions {
     setAllowFPReassociate(LO.AllowFPReassoc);
     setNoHonorNaNs(LO.NoHonorNaNs);
     setNoHonorInfs(LO.NoHonorInfs);
+    // Ensure that if FiniteMathOnly is enabled, NoHonorNaNs and NoHonorInfs are
+    // also enabled. This is because FiniteMathOnly mode assumes no NaNs or Infs
+    // are present in computations.
+    if (!LO.NoHonorInfs || !LO.NoHonorInfs)
+      assert(!LO.FiniteMathOnly && "FiniteMathOnly implies NoHonorInfs");
----------------
andykaylor wrote:

I agree with Aaron that we should get rid of the internal state that combines these two modes. I expect we'll only want to define `__FINITE_MATH_ONLY__` when we aren't honoring either. You could create code that made incorrect assumptions either way, but the state described by the symbol is that we aren't honoring either.

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


More information about the cfe-commits mailing list