Skip to content

Commit d7c7562

Browse files
authored
[clang][ExprConst] Call FastEvaluateAsRValue in isCXX11ConstantExpr (#151466)
This was one case where we didn't call `FastEvaluateAsRValue` before going through `EvaluateAsRValue`. Also replace the `EvalResult` parameter with an `APValue` one, since `FastEvaluateAsRVaule` only needs that. Small gains: https://llvm-compile-time-tracker.com/compare.php?from=112af8e62e734938547d50eeb7b416c8dd666f45&to=b2ea804b9e22b7f37eb1b07b01c0a8057275fe4a&stat=instructions:u
1 parent d204fdc commit d7c7562

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
@@ -16858,31 +16858,31 @@ static bool EvaluateAsRValue(EvalInfo &Info, const Expr *E, APValue &Result) {
1685816858
CheckMemoryLeaks(Info);
1685916859
}
1686016860

16861-
static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
16861+
static bool FastEvaluateAsRValue(const Expr *Exp, APValue &Result,
1686216862
const ASTContext &Ctx, bool &IsConst) {
1686316863
// Fast-path evaluations of integer literals, since we sometimes see files
1686416864
// containing vast quantities of these.
1686516865
if (const auto *L = dyn_cast<IntegerLiteral>(Exp)) {
16866-
Result.Val = APValue(APSInt(L->getValue(),
16867-
L->getType()->isUnsignedIntegerType()));
16866+
Result =
16867+
APValue(APSInt(L->getValue(), L->getType()->isUnsignedIntegerType()));
1686816868
IsConst = true;
1686916869
return true;
1687016870
}
1687116871

1687216872
if (const auto *L = dyn_cast<CXXBoolLiteralExpr>(Exp)) {
16873-
Result.Val = APValue(APSInt(APInt(1, L->getValue())));
16873+
Result = APValue(APSInt(APInt(1, L->getValue())));
1687416874
IsConst = true;
1687516875
return true;
1687616876
}
1687716877

1687816878
if (const auto *FL = dyn_cast<FloatingLiteral>(Exp)) {
16879-
Result.Val = APValue(FL->getValue());
16879+
Result = APValue(FL->getValue());
1688016880
IsConst = true;
1688116881
return true;
1688216882
}
1688316883

1688416884
if (const auto *L = dyn_cast<CharacterLiteral>(Exp)) {
16885-
Result.Val = APValue(Ctx.MakeIntValue(L->getValue(), L->getType()));
16885+
Result = APValue(Ctx.MakeIntValue(L->getValue(), L->getType()));
1688616886
IsConst = true;
1688716887
return true;
1688816888
}
@@ -16891,7 +16891,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
1689116891
if (CE->hasAPValueResult()) {
1689216892
APValue APV = CE->getAPValueResult();
1689316893
if (!APV.isLValue()) {
16894-
Result.Val = std::move(APV);
16894+
Result = std::move(APV);
1689516895
IsConst = true;
1689616896
return true;
1689716897
}
@@ -16921,7 +16921,7 @@ static bool EvaluateAsRValue(const Expr *E, Expr::EvalResult &Result,
1692116921
const ASTContext &Ctx, EvalInfo &Info) {
1692216922
assert(!E->isValueDependent());
1692316923
bool IsConst;
16924-
if (FastEvaluateAsRValue(E, Result, Ctx, IsConst))
16924+
if (FastEvaluateAsRValue(E, Result.Val, Ctx, IsConst))
1692516925
return IsConst;
1692616926

1692716927
return EvaluateAsRValue(Info, E, Result.Val);
@@ -17078,7 +17078,8 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx,
1707817078
assert(!isValueDependent() &&
1707917079
"Expression evaluator can't be called on a dependent expression.");
1708017080
bool IsConst;
17081-
if (FastEvaluateAsRValue(this, Result, Ctx, IsConst) && Result.Val.hasValue())
17081+
if (FastEvaluateAsRValue(this, Result.Val, Ctx, IsConst) &&
17082+
Result.Val.hasValue())
1708217083
return true;
1708317084

1708417085
ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr");
@@ -17293,7 +17294,7 @@ void Expr::EvaluateForOverflow(const ASTContext &Ctx) const {
1729317294
ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateForOverflow");
1729417295
bool IsConst;
1729517296
EvalResult EVResult;
17296-
if (!FastEvaluateAsRValue(this, EVResult, Ctx, IsConst)) {
17297+
if (!FastEvaluateAsRValue(this, EVResult.Val, Ctx, IsConst)) {
1729717298
EvalInfo Info(Ctx, EVResult, EvalInfo::EM_IgnoreSideEffects);
1729817299
Info.CheckingForUndefinedBehavior = true;
1729917300
(void)::EvaluateAsRValue(Info, this, EVResult.Val);
@@ -17813,9 +17814,8 @@ Expr::getIntegerConstantExpr(const ASTContext &Ctx) 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))
1782017820
return Value;
1782117821
return std::nullopt;
@@ -17854,13 +17854,20 @@ bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result) const {
1785417854
// issues.
1785517855
assert(Ctx.getLangOpts().CPlusPlus);
1785617856

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

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

0 commit comments

Comments
 (0)