[clang] [Clang] Add constexpr eval for cmath builtins (PR #194327)

via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 27 02:50:01 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- clang/test/SemaCXX/constexpr-cmath-builtins.cpp clang/lib/AST/ByteCode/InterpBuiltin.cpp clang/lib/AST/ExprConstant.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 27834d1bc..b58d3c386 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -829,7 +829,8 @@ static bool interp__builtin_modf(InterpState &S, CodePtr OpPC,
 
   if (Val.getAPFloat().isInfinity()) {
     Floating Fraction = S.allocFloat(Val.getAPFloat().getSemantics());
-    Fraction.copy(APFloat::getZero(Val.getAPFloat().getSemantics(), Val.getAPFloat().isNegative()));
+    Fraction.copy(APFloat::getZero(Val.getAPFloat().getSemantics(),
+                                   Val.getAPFloat().isNegative()));
     S.Stk.push<Floating>(Fraction);
     return true;
   }
@@ -940,7 +941,8 @@ static bool interp__builtin_remquo(InterpState &S, CodePtr OpPC,
   const Floating &LHS = S.Stk.pop<Floating>();
 
   APFloat Q = LHS.getAPFloat();
-  if (Q.divide(RHS.getAPFloat(), APFloat::rmNearestTiesToEven) & APFloat::opInvalidOp)
+  if (Q.divide(RHS.getAPFloat(), APFloat::rmNearestTiesToEven) &
+      APFloat::opInvalidOp)
     Q = APFloat::getZero(Q.getSemantics());
   else
     Q.roundToIntegral(APFloat::rmNearestTiesToEven);
@@ -1008,7 +1010,7 @@ static bool interp__builtin_lrint(InterpState &S, CodePtr OpPC,
   F.roundToIntegral(RM);
 
   APSInt IntVal(S.getASTContext().getTypeSize(Call->getType()),
-               Call->getType()->isUnsignedIntegerOrEnumerationType());
+                Call->getType()->isUnsignedIntegerOrEnumerationType());
   bool IsExact = false;
   APFloat::opStatus Status = F.convertToInteger(IntVal, RM, &IsExact);
 
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 926415159..df32df277 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -16396,7 +16396,7 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const CallExpr *E,
     FloatVal.roundToIntegral(RM);
 
     APSInt IntVal(Info.Ctx.getTypeSize(E->getType()),
-                 E->getType()->isUnsignedIntegerOrEnumerationType());
+                  E->getType()->isUnsignedIntegerOrEnumerationType());
     bool IsExact = false;
     APFloat::opStatus Status = FloatVal.convertToInteger(IntVal, RM, &IsExact);
 
@@ -20180,7 +20180,8 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) {
 
     APFloat ResultCopy = Result;
     bool LoseInfo = false;
-    ResultCopy.convert(RHS.getSemantics(), APFloat::rmNearestTiesToEven, &LoseInfo);
+    ResultCopy.convert(RHS.getSemantics(), APFloat::rmNearestTiesToEven,
+                       &LoseInfo);
     APFloat::cmpResult Res = ResultCopy.compare(RHS);
 
     if (Res == APFloat::cmpEqual)
@@ -20277,12 +20278,14 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) {
     else
       Q.roundToIntegral(APFloat::rmNearestTiesToEven);
 
-    APSInt QuoInt(Info.Ctx.getTypeSize(E->getArg(2)->getType()->getPointeeType()), false);
+    APSInt QuoInt(
+        Info.Ctx.getTypeSize(E->getArg(2)->getType()->getPointeeType()), false);
     bool IsExact = false;
     Q.convertToInteger(QuoInt, APFloat::rmTowardZero, &IsExact);
 
     APValue APV{QuoInt};
-    if (!handleAssignment(Info, E, QuoLVal, E->getArg(2)->getType()->getPointeeType(), APV))
+    if (!handleAssignment(Info, E, QuoLVal,
+                          E->getArg(2)->getType()->getPointeeType(), APV))
       return false;
 
     Result.remainder(RHS);

``````````

</details>


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


More information about the cfe-commits mailing list