Skip to content

Commit

Permalink
[clang][Interp] Allow recursive intepretation
Browse files Browse the repository at this point in the history
This shouldn't be a problem in general, but we used to have some
sanity checks that prevented it from working. Remove those and
only do them on the non-recursive calls instead.
  • Loading branch information
tbaederr committed Mar 1, 2024
1 parent 3034632 commit 18d2ff4
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions clang/lib/AST/Interp/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ bool Context::isPotentialConstantExpr(State &Parent, const FunctionDecl *FD) {
}

bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) {
assert(Stk.empty());
bool Recursing = !Stk.empty();
ByteCodeExprGen<EvalEmitter> C(*this, *P, Parent, Stk, Result);

auto Res = C.interpretExpr(E, /*ConvertResultToRValue=*/E->isGLValue());
Expand All @@ -51,20 +51,22 @@ bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) {
return false;
}

assert(Stk.empty());
if (!Recursing) {
assert(Stk.empty());
#ifndef NDEBUG
// Make sure we don't rely on some value being still alive in
// InterpStack memory.
Stk.clear();
// Make sure we don't rely on some value being still alive in
// InterpStack memory.
Stk.clear();
#endif
}

Result = Res.toAPValue();

return true;
}

bool Context::evaluate(State &Parent, const Expr *E, APValue &Result) {
assert(Stk.empty());
bool Recursing = !Stk.empty();
ByteCodeExprGen<EvalEmitter> C(*this, *P, Parent, Stk, Result);

auto Res = C.interpretExpr(E);
Expand All @@ -73,19 +75,22 @@ bool Context::evaluate(State &Parent, const Expr *E, APValue &Result) {
return false;
}

assert(Stk.empty());
if (!Recursing) {
assert(Stk.empty());
#ifndef NDEBUG
// Make sure we don't rely on some value being still alive in
// InterpStack memory.
Stk.clear();
// Make sure we don't rely on some value being still alive in
// InterpStack memory.
Stk.clear();
#endif
}

Result = Res.toAPValue();
return true;
}

bool Context::evaluateAsInitializer(State &Parent, const VarDecl *VD,
APValue &Result) {
assert(Stk.empty());
bool Recursing = !Stk.empty();
ByteCodeExprGen<EvalEmitter> C(*this, *P, Parent, Stk, Result);

bool CheckGlobalInitialized =
Expand All @@ -97,12 +102,14 @@ bool Context::evaluateAsInitializer(State &Parent, const VarDecl *VD,
return false;
}

assert(Stk.empty());
if (!Recursing) {
assert(Stk.empty());
#ifndef NDEBUG
// Make sure we don't rely on some value being still alive in
// InterpStack memory.
Stk.clear();
// Make sure we don't rely on some value being still alive in
// InterpStack memory.
Stk.clear();
#endif
}

Result = Res.toAPValue();
return true;
Expand Down

0 comments on commit 18d2ff4

Please sign in to comment.