[clang] [NFC] Add assertion to ensure that FiniteMathOnly toggles with (PR #97342)

Zahira Ammarguellat via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 1 12:57:57 PDT 2024


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

the values of HonorINFs and HonorNANs.

>From aea6519809340024226d587303e26c800c1a3756 Mon Sep 17 00:00:00 2001
From: Zahira Ammarguellat <zahira.ammarguellat at intel.com>
Date: Mon, 1 Jul 2024 12:56:07 -0700
Subject: [PATCH] [NFC] Add assertion to ensure that FiniteMathOnly toggles
 with the values of HonorINFs and HonorNANs.

---
 clang/include/clang/Basic/LangOptions.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h
index 91f1c2f2e6239..e866902743d2d 100644
--- a/clang/include/clang/Basic/LangOptions.h
+++ b/clang/include/clang/Basic/LangOptions.h
@@ -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");
     setNoSignedZero(LO.NoSignedZero);
     setAllowReciprocal(LO.AllowRecip);
     setAllowApproxFunc(LO.ApproxFunc);



More information about the cfe-commits mailing list