Skip to content

Commit b4343ab

Browse files
committed
[clang][ExprConst] Short-circuit ConstantExpr evaluation
ConstantExprs already have a value attached we can just return here. Differential Revision: https://reviews.llvm.org/D155548
1 parent 98eda5d commit b4343ab

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15327,6 +15327,17 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
1532715327
return true;
1532815328
}
1532915329

15330+
if (const auto *CE = dyn_cast<ConstantExpr>(Exp)) {
15331+
if (CE->hasAPValueResult()) {
15332+
Result.Val = CE->getAPValueResult();
15333+
IsConst = true;
15334+
return true;
15335+
}
15336+
15337+
// The SubExpr is usually just an IntegerLiteral.
15338+
return FastEvaluateAsRValue(CE->getSubExpr(), Result, Ctx, IsConst);
15339+
}
15340+
1533015341
// This case should be rare, but we need to check it before we check on
1533115342
// the type below.
1533215343
if (Exp->getType().isNull()) {

0 commit comments

Comments
 (0)