Skip to content

Commit c70fa55

Browse files
committed
[clang][Interp][NFC] Add cleanup() infrastructure to EvalEmitter
Unused for now.
1 parent a16d33e commit c70fa55

File tree

5 files changed

+15
-0
lines changed

5 files changed

+15
-0
lines changed

clang/lib/AST/Interp/Context.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ bool Context::evaluateAsRValue(State &Parent, const Expr *E, APValue &Result) {
4646
auto Res = C.interpretExpr(E, /*ConvertResultToRValue=*/E->isGLValue());
4747

4848
if (Res.isInvalid()) {
49+
C.cleanup();
4950
Stk.clear();
5051
return false;
5152
}
@@ -70,6 +71,7 @@ bool Context::evaluate(State &Parent, const Expr *E, APValue &Result) {
7071

7172
auto Res = C.interpretExpr(E);
7273
if (Res.isInvalid()) {
74+
C.cleanup();
7375
Stk.clear();
7476
return false;
7577
}
@@ -97,6 +99,7 @@ bool Context::evaluateAsInitializer(State &Parent, const VarDecl *VD,
9799
(VD->getType()->isRecordType() || VD->getType()->isArrayType());
98100
auto Res = C.interpretDecl(VD, CheckGlobalInitialized);
99101
if (Res.isInvalid()) {
102+
C.cleanup();
100103
Stk.clear();
101104
return false;
102105
}

clang/lib/AST/Interp/EvalEmitter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ EvalEmitter::~EvalEmitter() {
3232
}
3333
}
3434

35+
/// Clean up all our resources. This needs to done in failed evaluations before
36+
/// we call InterpStack::clear(), because there might be a Pointer on the stack
37+
/// pointing into a Block in the EvalEmitter.
38+
void EvalEmitter::cleanup() { S.cleanup(); }
39+
3540
EvaluationResult EvalEmitter::interpretExpr(const Expr *E,
3641
bool ConvertResultToRValue) {
3742
S.setEvalLocation(E->getExprLoc());

clang/lib/AST/Interp/EvalEmitter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ class EvalEmitter : public SourceMapper {
3838
bool ConvertResultToRValue = false);
3939
EvaluationResult interpretDecl(const VarDecl *VD, bool CheckFullyInitialized);
4040

41+
/// Clean up all resources.
42+
void cleanup();
43+
4144
InterpState &getState() { return S; }
4245

4346
protected:

clang/lib/AST/Interp/InterpState.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ InterpState::~InterpState() {
3333
}
3434
}
3535

36+
void InterpState::cleanup() {}
37+
3638
Frame *InterpState::getCurrentFrame() {
3739
if (Current && Current->Caller)
3840
return Current;

clang/lib/AST/Interp/InterpState.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ class InterpState final : public State, public SourceMapper {
3939

4040
~InterpState();
4141

42+
void cleanup();
43+
4244
InterpState(const InterpState &) = delete;
4345
InterpState &operator=(const InterpState &) = delete;
4446

0 commit comments

Comments
 (0)