Skip to content

Commit 2cb39ae

Browse files
committed
Fast
1 parent cc8c941 commit 2cb39ae

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16849,31 +16849,31 @@ static bool EvaluateAsRValue(EvalInfo &Info, const Expr *E, APValue &Result) {
1684916849
CheckMemoryLeaks(Info);
1685016850
}
1685116851

16852-
static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
16852+
static bool FastEvaluateAsRValue(const Expr *Exp, APValue &Result,
1685316853
const ASTContext &Ctx, bool &IsConst) {
1685416854
// Fast-path evaluations of integer literals, since we sometimes see files
1685516855
// containing vast quantities of these.
1685616856
if (const auto *L = dyn_cast<IntegerLiteral>(Exp)) {
16857-
Result.Val = APValue(APSInt(L->getValue(),
16858-
L->getType()->isUnsignedIntegerType()));
16857+
Result =
16858+
APValue(APSInt(L->getValue(), L->getType()->isUnsignedIntegerType()));
1685916859
IsConst = true;
1686016860
return true;
1686116861
}
1686216862

1686316863
if (const auto *L = dyn_cast<CXXBoolLiteralExpr>(Exp)) {
16864-
Result.Val = APValue(APSInt(APInt(1, L->getValue())));
16864+
Result = APValue(APSInt(APInt(1, L->getValue())));
1686516865
IsConst = true;
1686616866
return true;
1686716867
}
1686816868

1686916869
if (const auto *FL = dyn_cast<FloatingLiteral>(Exp)) {
16870-
Result.Val = APValue(FL->getValue());
16870+
Result = APValue(FL->getValue());
1687116871
IsConst = true;
1687216872
return true;
1687316873
}
1687416874

1687516875
if (const auto *L = dyn_cast<CharacterLiteral>(Exp)) {
16876-
Result.Val = APValue(Ctx.MakeIntValue(L->getValue(), L->getType()));
16876+
Result = APValue(Ctx.MakeIntValue(L->getValue(), L->getType()));
1687716877
IsConst = true;
1687816878
return true;
1687916879
}
@@ -16882,7 +16882,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
1688216882
if (CE->hasAPValueResult()) {
1688316883
APValue APV = CE->getAPValueResult();
1688416884
if (!APV.isLValue()) {
16885-
Result.Val = std::move(APV);
16885+
Result = std::move(APV);
1688616886
IsConst = true;
1688716887
return true;
1688816888
}
@@ -16912,7 +16912,7 @@ static bool EvaluateAsRValue(const Expr *E, Expr::EvalResult &Result,
1691216912
const ASTContext &Ctx, EvalInfo &Info) {
1691316913
assert(!E->isValueDependent());
1691416914
bool IsConst;
16915-
if (FastEvaluateAsRValue(E, Result, Ctx, IsConst))
16915+
if (FastEvaluateAsRValue(E, Result.Val, Ctx, IsConst))
1691616916
return IsConst;
1691716917

1691816918
return EvaluateAsRValue(Info, E, Result.Val);
@@ -17069,7 +17069,8 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx,
1706917069
assert(!isValueDependent() &&
1707017070
"Expression evaluator can't be called on a dependent expression.");
1707117071
bool IsConst;
17072-
if (FastEvaluateAsRValue(this, Result, Ctx, IsConst) && Result.Val.hasValue())
17072+
if (FastEvaluateAsRValue(this, Result.Val, Ctx, IsConst) &&
17073+
Result.Val.hasValue())
1707317074
return true;
1707417075

1707517076
ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr");
@@ -17284,7 +17285,7 @@ void Expr::EvaluateForOverflow(const ASTContext &Ctx) const {
1728417285
ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateForOverflow");
1728517286
bool IsConst;
1728617287
EvalResult EVResult;
17287-
if (!FastEvaluateAsRValue(this, EVResult, Ctx, IsConst)) {
17288+
if (!FastEvaluateAsRValue(this, EVResult.Val, Ctx, IsConst)) {
1728817289
EvalInfo Info(Ctx, EVResult, EvalInfo::EM_IgnoreSideEffects);
1728917290
Info.CheckingForUndefinedBehavior = true;
1729017291
(void)::EvaluateAsRValue(Info, this, EVResult.Val);
@@ -17813,9 +17814,8 @@ Expr::getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc) const {
1781317814
return std::nullopt;
1781417815
}
1781517816

17816-
APSInt Value;
17817-
1781817817
if (Ctx.getLangOpts().CPlusPlus11) {
17818+
APSInt Value;
1781917819
if (EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, &Value, Loc))
1782017820
return Value;
1782117821
return std::nullopt;
@@ -17855,13 +17855,20 @@ bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result,
1785517855
// issues.
1785617856
assert(Ctx.getLangOpts().CPlusPlus);
1785717857

17858+
bool IsConst;
17859+
APValue Scratch;
17860+
if (FastEvaluateAsRValue(this, Scratch, Ctx, IsConst) && Scratch.hasValue()) {
17861+
if (Result)
17862+
*Result = Scratch;
17863+
return true;
17864+
}
17865+
1785817866
// Build evaluation settings.
1785917867
Expr::EvalStatus Status;
1786017868
SmallVector<PartialDiagnosticAt, 8> Diags;
1786117869
Status.Diag = &Diags;
1786217870
EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantExpression);
1786317871

17864-
APValue Scratch;
1786517872
bool IsConstExpr =
1786617873
::EvaluateAsRValue(Info, this, Result ? *Result : Scratch) &&
1786717874
// FIXME: We don't produce a diagnostic for this, but the callers that

0 commit comments

Comments
 (0)