Skip to content

Commit

Permalink
[clang][ExprConst] Short-circuit ConstantExpr evaluation
Browse files Browse the repository at this point in the history
ConstantExprs already have a value attached we can just return here.

Differential Revision: https://reviews.llvm.org/D155548
  • Loading branch information
tbaederr committed Oct 10, 2023
1 parent 98eda5d commit b4343ab
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions clang/lib/AST/ExprConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15327,6 +15327,17 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
return true;
}

if (const auto *CE = dyn_cast<ConstantExpr>(Exp)) {
if (CE->hasAPValueResult()) {
Result.Val = CE->getAPValueResult();
IsConst = true;
return true;
}

// The SubExpr is usually just an IntegerLiteral.
return FastEvaluateAsRValue(CE->getSubExpr(), Result, Ctx, IsConst);
}

// This case should be rare, but we need to check it before we check on
// the type below.
if (Exp->getType().isNull()) {
Expand Down

0 comments on commit b4343ab

Please sign in to comment.