[clang] [libc] [llvm] [clang] Make __builtin_exp and __builtin_expf constexpr. (PR #199808)

Hubert Tong via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 24 21:37:49 PDT 2026


================
@@ -2707,27 +2707,31 @@ static bool checkFloatingPointResult(EvalInfo &Info, const Expr *E,
   if (Info.InConstantContext)
     return true;
 
+  // The output result is exact and no exceptions are raised, so it is safe to
+  // perform compile-time evaluation.
+  if (St == APFloat::opOK)
+    return true;
+
   FPOptions FPO = E->getFPFeaturesInEffect(Info.getLangOpts());
-  if ((St & APFloat::opInexact) &&
-      FPO.getRoundingMode() == llvm::RoundingMode::Dynamic) {
-    // Inexact result means that it depends on rounding mode. If the requested
-    // mode is dynamic, the evaluation cannot be made in compile time.
+
+  if (FPO.getRoundingMode() == llvm::RoundingMode::Dynamic) {
+    // Some floating point exception is raised, so the result might depend on
+    // rounding mode. If the requested mode is dynamic, the evaluation cannot
+    // be made in compile time.
----------------
hubert-reinterpretcast wrote:

I don't think dynamic rounding mode should suppress compile-time folding because of floating point exceptions other than "inexact". For example, exact infinities associated with division by zero should be fine. I agree, however, that this issue is not new to this PR. Please add at least a FIXME.

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


More information about the cfe-commits mailing list