[clang] [NFC] Add assertion to ensure FiniteMathOnly is in sync with HonorINFs and HonorNANs. (PR #97342)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 2 06:58:39 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");
----------------
AaronBallman wrote:
How about:
```
assert((LO.FiniteMathOnly == (LO.NoHonorInfs && LO.NoHonorNans)) && "inf/nan inconsistent internal state");
```
to make it more clear that the state has to be sane no matter which options are set? Also, this corrects the duplicate condition in your `if` statement.
https://github.com/llvm/llvm-project/pull/97342
More information about the cfe-commits
mailing list