@@ -16858,31 +16858,31 @@ static bool EvaluateAsRValue(EvalInfo &Info, const Expr *E, APValue &Result) {
16858
16858
CheckMemoryLeaks(Info);
16859
16859
}
16860
16860
16861
- static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
16861
+ static bool FastEvaluateAsRValue(const Expr *Exp, APValue &Result,
16862
16862
const ASTContext &Ctx, bool &IsConst) {
16863
16863
// Fast-path evaluations of integer literals, since we sometimes see files
16864
16864
// containing vast quantities of these.
16865
16865
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()));
16868
16868
IsConst = true;
16869
16869
return true;
16870
16870
}
16871
16871
16872
16872
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())));
16874
16874
IsConst = true;
16875
16875
return true;
16876
16876
}
16877
16877
16878
16878
if (const auto *FL = dyn_cast<FloatingLiteral>(Exp)) {
16879
- Result.Val = APValue(FL->getValue());
16879
+ Result = APValue(FL->getValue());
16880
16880
IsConst = true;
16881
16881
return true;
16882
16882
}
16883
16883
16884
16884
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()));
16886
16886
IsConst = true;
16887
16887
return true;
16888
16888
}
@@ -16891,7 +16891,7 @@ static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
16891
16891
if (CE->hasAPValueResult()) {
16892
16892
APValue APV = CE->getAPValueResult();
16893
16893
if (!APV.isLValue()) {
16894
- Result.Val = std::move(APV);
16894
+ Result = std::move(APV);
16895
16895
IsConst = true;
16896
16896
return true;
16897
16897
}
@@ -16921,7 +16921,7 @@ static bool EvaluateAsRValue(const Expr *E, Expr::EvalResult &Result,
16921
16921
const ASTContext &Ctx, EvalInfo &Info) {
16922
16922
assert(!E->isValueDependent());
16923
16923
bool IsConst;
16924
- if (FastEvaluateAsRValue(E, Result, Ctx, IsConst))
16924
+ if (FastEvaluateAsRValue(E, Result.Val , Ctx, IsConst))
16925
16925
return IsConst;
16926
16926
16927
16927
return EvaluateAsRValue(Info, E, Result.Val);
@@ -17078,7 +17078,8 @@ bool Expr::EvaluateAsConstantExpr(EvalResult &Result, const ASTContext &Ctx,
17078
17078
assert(!isValueDependent() &&
17079
17079
"Expression evaluator can't be called on a dependent expression.");
17080
17080
bool IsConst;
17081
- if (FastEvaluateAsRValue(this, Result, Ctx, IsConst) && Result.Val.hasValue())
17081
+ if (FastEvaluateAsRValue(this, Result.Val, Ctx, IsConst) &&
17082
+ Result.Val.hasValue())
17082
17083
return true;
17083
17084
17084
17085
ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateAsConstantExpr");
@@ -17293,7 +17294,7 @@ void Expr::EvaluateForOverflow(const ASTContext &Ctx) const {
17293
17294
ExprTimeTraceScope TimeScope(this, Ctx, "EvaluateForOverflow");
17294
17295
bool IsConst;
17295
17296
EvalResult EVResult;
17296
- if (!FastEvaluateAsRValue(this, EVResult, Ctx, IsConst)) {
17297
+ if (!FastEvaluateAsRValue(this, EVResult.Val , Ctx, IsConst)) {
17297
17298
EvalInfo Info(Ctx, EVResult, EvalInfo::EM_IgnoreSideEffects);
17298
17299
Info.CheckingForUndefinedBehavior = true;
17299
17300
(void)::EvaluateAsRValue(Info, this, EVResult.Val);
@@ -17813,9 +17814,8 @@ Expr::getIntegerConstantExpr(const ASTContext &Ctx) const {
17813
17814
return std::nullopt;
17814
17815
}
17815
17816
17816
- APSInt Value;
17817
-
17818
17817
if (Ctx.getLangOpts().CPlusPlus11) {
17818
+ APSInt Value;
17819
17819
if (EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, &Value))
17820
17820
return Value;
17821
17821
return std::nullopt;
@@ -17854,13 +17854,20 @@ bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result) const {
17854
17854
// issues.
17855
17855
assert(Ctx.getLangOpts().CPlusPlus);
17856
17856
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
+
17857
17865
// Build evaluation settings.
17858
17866
Expr::EvalStatus Status;
17859
17867
SmallVector<PartialDiagnosticAt, 8> Diags;
17860
17868
Status.Diag = &Diags;
17861
17869
EvalInfo Info(Ctx, Status, EvalInfo::EM_ConstantExpression);
17862
17870
17863
- APValue Scratch;
17864
17871
bool IsConstExpr =
17865
17872
::EvaluateAsRValue(Info, this, Result ? *Result : Scratch) &&
17866
17873
// FIXME: We don't produce a diagnostic for this, but the callers that
0 commit comments