[PATCH] D138115: [clang] Short-circuit evaluation in ::EvaluateAsConstantExpr

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 17 03:02:20 PST 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGec782951d7bd: [clang] Short-circuit evaluation in ::EvaluateAsConstantExpr (authored by tbaeder).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138115/new/

https://reviews.llvm.org/D138115

Files:
  clang/lib/AST/ExprConstant.cpp


Index: clang/lib/AST/ExprConstant.cpp
===================================================================
--- clang/lib/AST/ExprConstant.cpp
+++ clang/lib/AST/ExprConstant.cpp
@@ -15051,6 +15051,12 @@
     return true;
   }
 
+  if (const auto *L = dyn_cast<CXXBoolLiteralExpr>(Exp)) {
+    Result.Val = APValue(APSInt(APInt(1, L->getValue())));
+    IsConst = true;
+    return true;
+  }
+
   // This case should be rare, but we need to check it before we check on
   // the type below.
   if (Exp->getType().isNull()) {
@@ -15235,6 +15241,9 @@
                                   ConstantExprKind Kind) const {
   assert(!isValueDependent() &&
          "Expression evaluator can't be called on a dependent expression.");
+  bool IsConst;
+  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))
+    return true;
 
   ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr");
   EvalInfo::EvaluationMode EM = EvalInfo::EM_ConstantExpression;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138115.476066.patch
Type: text/x-patch
Size: 954 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221117/270ed9df/attachment-0001.bin>


More information about the cfe-commits mailing list