https://github.com/tbaederr updated https://github.com/llvm/llvm-project/pull/151466
>From 63cc1402357f86e04593027ac048ec4dc33c6640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com> Date: Thu, 31 Jul 2025 06:46:51 +0200 Subject: [PATCH] Fast --- clang/lib/AST/ExprConstant.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 244fd92a1ac17..20b7c447956b4 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -16858,31 +16858,31 @@ static bool EvaluateAsRValue(EvalInfo &Info, const Expr *E, APValue &Result) { CheckMemoryLeaks(Info); } -static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result, +static bool FastEvaluateAsRValue(const Expr *Exp, APValue &Result, const ASTContext &Ctx, bool &IsConst) { // Fast-path evaluations of integer literals, since we sometimes see files // containing vast quantities of these. if (const auto *L = dyn_cast<IntegerLiteral>(Exp)) { - Result.Val = APValue(APSInt(L->getValue(), - L->getType()->isUnsignedIntegerType())); + Result = + APValue(APSInt(L->getValue(), L->getType()->isUnsignedIntegerType())); IsConst = true; return true; } if (const auto *L = dyn_cast<CXXBoolLiteralExpr>(Exp)) { - Result.Val = APValue(APSInt(APInt(1, L->getValue()))); + Result = APValue(APSInt(APInt(1, L->getValue()))); IsConst = true; return true; } if (const auto *FL = dyn_cast<FloatingLiteral>(Exp)) { - Result.Val = APValue(FL->getValue()); + Result = APValue(FL->getValue()); IsConst = true; return true; } if (const auto *L = dyn_cast<CharacterLiteral>(Exp)) { - Result.Val = APValue(Ctx.MakeIntValue(L->getValue(), L->getType())); + Result = APValue(Ctx.MakeIntValue(L->getValue(), L->getType())); IsConst = true; return true; } @@ -16891,7 +16891,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result, if (CE->hasAPValueResult()) { APValue APV = CE->getAPValueResult(); if (!APV.isLValue()) { - Result.Val = std::move(APV); + Result = std::move(APV); IsConst = true; return true; } @@ -16921,7 +16921,7 @@ static bool EvaluateAsRValue(const Expr *E, Expr::EvalResult &Result, const ASTContext &Ctx, EvalInfo &Info) { assert(!E->isValueDependent()); bool IsConst; - if (FastEvaluateAsRValue(E, Result, Ctx, IsConst)) + if (FastEvaluateAsRValue(E, Result.Val, Ctx, IsConst)) return IsConst; return EvaluateAsRValue(Info, E, Result.Val); @@ -17078,7 +17078,8 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx, assert(!isValueDependent() && "Expression evaluator can't be called on a dependent expression."); bool IsConst; - if (FastEvaluateAsRValue(this, Result, Ctx, IsConst) && Result.Val.hasValue()) + if (FastEvaluateAsRValue(this, Result.Val, Ctx, IsConst) && + Result.Val.hasValue()) return true; ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr"); @@ -17293,7 +17294,7 @@ void Expr::EvaluateForOverflow(const ASTContext &Ctx) const { ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateForOverflow"); bool IsConst; EvalResult EVResult; - if (!FastEvaluateAsRValue(this, EVResult, Ctx, IsConst)) { + if (!FastEvaluateAsRValue(this, EVResult.Val, Ctx, IsConst)) { EvalInfo Info(Ctx, EVResult, EvalInfo::EM_IgnoreSideEffects); Info.CheckingForUndefinedBehavior = true; (void)::EvaluateAsRValue(Info, this, EVResult.Val); @@ -17813,9 +17814,8 @@ Expr::getIntegerConstantExpr(const ASTContext &Ctx) const { return std::nullopt; } - APSInt Value; - if (Ctx.getLangOpts().CPlusPlus11) { + APSInt Value; if (EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, &Value)) return Value; return std::nullopt; @@ -17854,13 +17854,20 @@ bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result) const { // issues. assert(Ctx.getLangOpts().CPlusPlus); + bool IsConst; + APValue Scratch; + if (FastEvaluateAsRValue(this, Scratch, Ctx, IsConst) && Scratch.hasValue()) { + if (Result) + *Result = Scratch; + return true; + } + // Build evaluation settings. Expr::EvalStatus Status; SmallVector<PartialDiagnosticAt, 8> Diags; Status.Diag = &Diags; EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantExpression); - APValue Scratch; bool IsConstExpr = ::EvaluateAsRValue(Info, this, Result ? *Result : Scratch) && // FIXME: We don't produce a diagnostic for this, but the callers that _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits