[clang][Interp][NFC] Add assertions to VM entry points
Assert that the previous call left the stack empty, as well as that successful interpretations leave an empty stack.
This commit is contained in:
parent
d78a3957ea
commit
c01ac372fc
|
@ -27,6 +27,7 @@ Context::Context(ASTContext &Ctx) : Ctx(Ctx), P(new Program(*this)) {}
|
||||||
Context::~Context() {}
|
Context::~Context() {}
|
||||||
|
|
||||||
bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) {
|
bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) {
|
||||||
|
assert(Stk.empty());
|
||||||
Function *Func = P->getFunction(FD);
|
Function *Func = P->getFunction(FD);
|
||||||
if (!Func) {
|
if (!Func) {
|
||||||
if (auto R = ByteCodeStmtGen<ByteCodeEmitter>(*this, *P).compileFunc(FD)) {
|
if (auto R = ByteCodeStmtGen<ByteCodeEmitter>(*this, *P).compileFunc(FD)) {
|
||||||
|
@ -45,14 +46,28 @@ bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) {
|
bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) {
|
||||||
|
assert(Stk.empty());
|
||||||
ByteCodeExprGen<EvalEmitter> C(*this, *P, Parent, Stk, Result);
|
ByteCodeExprGen<EvalEmitter> C(*this, *P, Parent, Stk, Result);
|
||||||
return Check(Parent, C.interpretExpr(E));
|
if (Check(Parent, C.interpretExpr(E))) {
|
||||||
|
assert(Stk.empty());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stk.clear();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Context::evaluateAsInitializer(State &Parent, const VarDecl *VD,
|
bool Context::evaluateAsInitializer(State &Parent, const VarDecl *VD,
|
||||||
APValue &Result) {
|
APValue &Result) {
|
||||||
|
assert(Stk.empty());
|
||||||
ByteCodeExprGen<EvalEmitter> C(*this, *P, Parent, Stk, Result);
|
ByteCodeExprGen<EvalEmitter> C(*this, *P, Parent, Stk, Result);
|
||||||
return Check(Parent, C.interpretDecl(VD));
|
if (Check(Parent, C.interpretDecl(VD))) {
|
||||||
|
assert(Stk.empty());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Stk.clear();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const LangOptions &Context::getLangOpts() const { return Ctx.getLangOpts(); }
|
const LangOptions &Context::getLangOpts() const { return Ctx.getLangOpts(); }
|
||||||
|
|
|
@ -75,6 +75,9 @@ public:
|
||||||
/// Clears the stack without calling any destructors.
|
/// Clears the stack without calling any destructors.
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
// Returns whether the stack is empty.
|
||||||
|
bool empty() const { return StackSize == 0; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// All stack slots are aligned to the native pointer alignment for storage.
|
/// All stack slots are aligned to the native pointer alignment for storage.
|
||||||
/// The size of an object is rounded up to a pointer alignment multiple.
|
/// The size of an object is rounded up to a pointer alignment multiple.
|
||||||
|
|
Loading…
Reference in New Issue