Skip to content

Commit

Permalink
[clang] Short-circuit evaluation in ::EvaluateAsConstantExpr
Browse files Browse the repository at this point in the history
Use FastEvaluateAsRValue() in EvaluateAsConstantExpr() as well, to
short-circuit evaluation of simple integrals.

Differential Revision: https://reviews.llvm.org/D138115
  • Loading branch information
tbaederr committed Nov 17, 2022
1 parent 303d14f commit ec78295
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions clang/lib/AST/ExprConstant.cpp
Expand Up @@ -15051,6 +15051,12 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
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()) {
Expand Down Expand Up @@ -15235,6 +15241,9 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx,
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;
Expand Down

0 comments on commit ec78295

Please sign in to comment.