Author: Timm Bäder Date: 2022-11-17T12:01:37+01:00 New Revision: ec782951d7bd34f9c32d08bb6ec6b43d2a805832
URL: https://github.com/llvm/llvm-project/commit/ec782951d7bd34f9c32d08bb6ec6b43d2a805832 DIFF: https://github.com/llvm/llvm-project/commit/ec782951d7bd34f9c32d08bb6ec6b43d2a805832.diff LOG: [clang] Short-circuit evaluation in ::EvaluateAsConstantExpr Use FastEvaluateAsRValue() in EvaluateAsConstantExpr() as well, to short-circuit evaluation of simple integrals. Differential Revision: https://reviews.llvm.org/D138115 Added: Modified: clang/lib/AST/ExprConstant.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index ecf072e070835..b5281a660bcf3 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -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()) { @@ -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; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits