@@ -1856,12 +1856,8 @@ void CallStackFrame::describe(raw_ostream &Out) {
1856
1856
Out << ", ";
1857
1857
1858
1858
const ParmVarDecl *Param = *I;
1859
- if (Arguments) {
1860
- const APValue &Arg = Arguments[ArgIndex];
1861
- Arg.printPretty(Out, Info.Ctx, Param->getType());
1862
- } else {
1863
- Out << "<...>";
1864
- }
1859
+ const APValue &Arg = Arguments[ArgIndex];
1860
+ Arg.printPretty(Out, Info.Ctx, Param->getType());
1865
1861
1866
1862
if (ArgIndex == 0 && IsMemberCall)
1867
1863
Out << "->" << *Callee << '(';
@@ -5796,8 +5792,6 @@ typedef SmallVector<APValue, 8> ArgVector;
5796
5792
/// EvaluateArgs - Evaluate the arguments to a function call.
5797
5793
static bool EvaluateArgs(ArrayRef<const Expr *> Args, ArgVector &ArgValues,
5798
5794
EvalInfo &Info, const FunctionDecl *Callee) {
5799
- ArgValues.resize(Args.size());
5800
-
5801
5795
bool Success = true;
5802
5796
llvm::SmallBitVector ForbiddenNullArgs;
5803
5797
if (Callee->hasAttr<NonNullAttr>()) {
@@ -5815,6 +5809,8 @@ static bool EvaluateArgs(ArrayRef<const Expr *> Args, ArgVector &ArgValues,
5815
5809
}
5816
5810
}
5817
5811
}
5812
+ // FIXME: This is the wrong evaluation order for an assignment operator
5813
+ // called via operator syntax.
5818
5814
for (unsigned Idx = 0; Idx < Args.size(); Idx++) {
5819
5815
if (!Evaluate(ArgValues[Idx], Info, Args[Idx])) {
5820
5816
// If we're checking for a potential constant expression, evaluate all
@@ -5838,13 +5834,17 @@ static bool EvaluateArgs(ArrayRef<const Expr *> Args, ArgVector &ArgValues,
5838
5834
/// Evaluate a function call.
5839
5835
static bool HandleFunctionCall(SourceLocation CallLoc,
5840
5836
const FunctionDecl *Callee, const LValue *This,
5841
- ArrayRef<const Expr *> Args, APValue *ArgValues,
5842
- const Stmt *Body, EvalInfo &Info,
5843
- APValue &Result, const LValue *ResultSlot) {
5837
+ ArrayRef<const Expr*> Args, const Stmt *Body,
5838
+ EvalInfo &Info, APValue &Result,
5839
+ const LValue *ResultSlot) {
5840
+ ArgVector ArgValues(Args.size());
5841
+ if (!EvaluateArgs(Args, ArgValues, Info, Callee))
5842
+ return false;
5843
+
5844
5844
if (!Info.CheckCallLimit(CallLoc))
5845
5845
return false;
5846
5846
5847
- CallStackFrame Frame(Info, CallLoc, Callee, This, ArgValues);
5847
+ CallStackFrame Frame(Info, CallLoc, Callee, This, ArgValues.data() );
5848
5848
5849
5849
// For a trivial copy or move assignment, perform an APValue copy. This is
5850
5850
// essential for unions, where the operations performed by the assignment
@@ -7293,8 +7293,6 @@ class ExprEvaluatorBase
7293
7293
auto Args = llvm::makeArrayRef(E->getArgs(), E->getNumArgs());
7294
7294
bool HasQualifier = false;
7295
7295
7296
- ArgVector ArgValues;
7297
-
7298
7296
// Extract function decl and 'this' pointer from the callee.
7299
7297
if (CalleeType->isSpecificBuiltinType(BuiltinType::BoundMember)) {
7300
7298
const CXXMethodDecl *Member = nullptr;
@@ -7343,22 +7341,6 @@ class ExprEvaluatorBase
7343
7341
return Error(E);
7344
7342
}
7345
7343
7346
- // For an (overloaded) assignment expression, evaluate the RHS before the
7347
- // LHS.
7348
- auto *OCE = dyn_cast<CXXOperatorCallExpr>(E);
7349
- if (OCE && OCE->isAssignmentOp()) {
7350
- assert(Args.size() == 2 && "wrong number of arguments in assignment");
7351
- if (isa<CXXMethodDecl>(FD)) {
7352
- // Args[0] is the object argument.
7353
- if (!EvaluateArgs({Args[1]}, ArgValues, Info, FD))
7354
- return false;
7355
- } else {
7356
- if (!EvaluateArgs({Args[1], Args[0]}, ArgValues, Info, FD))
7357
- return false;
7358
- std::swap(ArgValues[0], ArgValues[1]);
7359
- }
7360
- }
7361
-
7362
7344
// Overloaded operator calls to member functions are represented as normal
7363
7345
// calls with '*this' as the first argument.
7364
7346
const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(FD);
@@ -7421,11 +7403,6 @@ class ExprEvaluatorBase
7421
7403
} else
7422
7404
return Error(E);
7423
7405
7424
- // Evaluate the arguments now if we've not already done so.
7425
- if (ArgValues.empty() && !Args.empty() &&
7426
- !EvaluateArgs(Args, ArgValues, Info, FD))
7427
- return false;
7428
-
7429
7406
SmallVector<QualType, 4> CovariantAdjustmentPath;
7430
7407
if (This) {
7431
7408
auto *NamedMember = dyn_cast<CXXMethodDecl>(FD);
@@ -7447,7 +7424,6 @@ class ExprEvaluatorBase
7447
7424
// Destructor calls are different enough that they have their own codepath.
7448
7425
if (auto *DD = dyn_cast<CXXDestructorDecl>(FD)) {
7449
7426
assert(This && "no 'this' pointer for destructor call");
7450
- assert(ArgValues.empty() && "unexpected destructor arguments");
7451
7427
return HandleDestruction(Info, E, *This,
7452
7428
Info.Ctx.getRecordType(DD->getParent()));
7453
7429
}
@@ -7456,8 +7432,8 @@ class ExprEvaluatorBase
7456
7432
Stmt *Body = FD->getBody(Definition);
7457
7433
7458
7434
if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition, Body) ||
7459
- !HandleFunctionCall(E->getExprLoc(), Definition, This, Args,
7460
- ArgValues.data(), Body, Info, Result, ResultSlot))
7435
+ !HandleFunctionCall(E->getExprLoc(), Definition, This, Args, Body, Info,
7436
+ Result, ResultSlot))
7461
7437
return false;
7462
7438
7463
7439
if (!CovariantAdjustmentPath.empty() &&
@@ -8095,20 +8071,17 @@ bool LValueExprEvaluator::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
8095
8071
if (E->getBase()->getType()->isVectorType())
8096
8072
return Error(E);
8097
8073
8098
- APSInt Index;
8099
8074
bool Success = true;
8100
-
8101
- // C++17's rules require us to evaluate the LHS first, regardless of which
8102
- // side is the base.
8103
- for (const Expr *SubExpr : {E->getLHS(), E->getRHS()}) {
8104
- if (SubExpr == E->getBase() ? !evaluatePointer(SubExpr, Result)
8105
- : !EvaluateInteger(SubExpr, Index, Info)) {
8106
- if (!Info.noteFailure())
8107
- return false;
8108
- Success = false;
8109
- }
8075
+ if (!evaluatePointer(E->getBase(), Result)) {
8076
+ if (!Info.noteFailure())
8077
+ return false;
8078
+ Success = false;
8110
8079
}
8111
8080
8081
+ APSInt Index;
8082
+ if (!EvaluateInteger(E->getIdx(), Index, Info))
8083
+ return false;
8084
+
8112
8085
return Success &&
8113
8086
HandleLValueArrayAdjustment(Info, E, Result, E->getType(), Index);
8114
8087
}
@@ -8152,10 +8125,7 @@ bool LValueExprEvaluator::VisitCompoundAssignOperator(
8152
8125
if (!Info.getLangOpts().CPlusPlus14 && !Info.keepEvaluatingAfterFailure())
8153
8126
return Error(CAO);
8154
8127
8155
- // C++17 onwards require that we evaluate the RHS first.
8156
8128
APValue RHS;
8157
- if (!Evaluate(RHS, this->Info, CAO->getRHS()))
8158
- return false;
8159
8129
8160
8130
// The overall lvalue result is the result of evaluating the LHS.
8161
8131
if (!this->Visit(CAO->getLHS())) {
@@ -8164,6 +8134,9 @@ bool LValueExprEvaluator::VisitCompoundAssignOperator(
8164
8134
return false;
8165
8135
}
8166
8136
8137
+ if (!Evaluate(RHS, this->Info, CAO->getRHS()))
8138
+ return false;
8139
+
8167
8140
return handleCompoundAssignment(
8168
8141
this->Info, CAO,
8169
8142
Result, CAO->getLHS()->getType(), CAO->getComputationLHSType(),
@@ -8174,17 +8147,17 @@ bool LValueExprEvaluator::VisitBinAssign(const BinaryOperator *E) {
8174
8147
if (!Info.getLangOpts().CPlusPlus14 && !Info.keepEvaluatingAfterFailure())
8175
8148
return Error(E);
8176
8149
8177
- // C++17 onwards require that we evaluate the RHS first.
8178
8150
APValue NewVal;
8179
- if (!Evaluate(NewVal, this->Info, E->getRHS()))
8180
- return false;
8181
8151
8182
8152
if (!this->Visit(E->getLHS())) {
8183
8153
if (Info.noteFailure())
8184
8154
Evaluate(NewVal, this->Info, E->getRHS());
8185
8155
return false;
8186
8156
}
8187
8157
8158
+ if (!Evaluate(NewVal, this->Info, E->getRHS()))
8159
+ return false;
8160
+
8188
8161
if (Info.getLangOpts().CPlusPlus20 &&
8189
8162
!HandleUnionActiveMemberChange(Info, E->getLHS(), Result))
8190
8163
return false;
@@ -15297,8 +15270,7 @@ bool Expr::isPotentialConstantExpr(const FunctionDecl *FD,
15297
15270
} else {
15298
15271
SourceLocation Loc = FD->getLocation();
15299
15272
HandleFunctionCall(Loc, FD, (MD && MD->isInstance()) ? &This : nullptr,
15300
- Args, /*ArgValues*/ nullptr, FD->getBody(), Info,
15301
- Scratch, nullptr);
15273
+ Args, FD->getBody(), Info, Scratch, nullptr);
15302
15274
}
15303
15275
15304
15276
return Diags.empty();
@@ -15320,8 +15292,13 @@ bool Expr::isPotentialConstantExprUnevaluated(Expr *E,
15320
15292
Info.CheckingPotentialConstantExpression = true;
15321
15293
15322
15294
// Fabricate a call stack frame to give the arguments a plausible cover story.
15323
- CallStackFrame Frame(Info, SourceLocation(), FD, /*This*/ nullptr,
15324
- /*ArgValues*/ nullptr);
15295
+ ArrayRef<const Expr*> Args;
15296
+ ArgVector ArgValues(0);
15297
+ bool Success = EvaluateArgs(Args, ArgValues, Info, FD);
15298
+ (void)Success;
15299
+ assert(Success &&
15300
+ "Failed to set up arguments for potential constant evaluation");
15301
+ CallStackFrame Frame(Info, SourceLocation(), FD, nullptr, ArgValues.data());
15325
15302
15326
15303
APValue ResultScratch;
15327
15304
Evaluate(ResultScratch, Info, E);
0 commit comments