Skip to content

Commit cc4dd01

Browse files
authored
[clang][bytecode][NFC] Remove VariableScope::emitDestruction (#169148)
destroyLocals() does the same thing.
1 parent 2e424de commit cc4dd01

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5939,8 +5939,10 @@ bool Compiler<Emitter>::visitBreakStmt(const BreakStmt *S) {
59395939
assert(TargetLabel);
59405940

59415941
for (VariableScope<Emitter> *C = this->VarScope; C != BreakScope;
5942-
C = C->getParent())
5943-
C->emitDestruction();
5942+
C = C->getParent()) {
5943+
if (!C->destroyLocals())
5944+
return false;
5945+
}
59445946

59455947
return this->jump(*TargetLabel);
59465948
}
@@ -5974,8 +5976,10 @@ bool Compiler<Emitter>::visitContinueStmt(const ContinueStmt *S) {
59745976
assert(TargetLabel);
59755977

59765978
for (VariableScope<Emitter> *C = VarScope; C != ContinueScope;
5977-
C = C->getParent())
5978-
C->emitDestruction();
5979+
C = C->getParent()) {
5980+
if (!C->destroyLocals())
5981+
return false;
5982+
}
59795983

59805984
return this->jump(*TargetLabel);
59815985
}
@@ -7159,9 +7163,12 @@ bool Compiler<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) {
71597163
return this->visitDeclRef(D, E);
71607164
}
71617165

7162-
template <class Emitter> void Compiler<Emitter>::emitCleanup() {
7163-
for (VariableScope<Emitter> *C = VarScope; C; C = C->getParent())
7164-
C->emitDestruction();
7166+
template <class Emitter> bool Compiler<Emitter>::emitCleanup() {
7167+
for (VariableScope<Emitter> *C = VarScope; C; C = C->getParent()) {
7168+
if (!C->destroyLocals())
7169+
return false;
7170+
}
7171+
return true;
71657172
}
71667173

71677174
template <class Emitter>

clang/lib/AST/ByteCode/Compiler.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
258258

259259
protected:
260260
/// Emits scope cleanup instructions.
261-
void emitCleanup();
261+
bool emitCleanup();
262262

263263
/// Returns a record type from a record or pointer type.
264264
const RecordType *getRecordTy(QualType Ty);
@@ -524,7 +524,6 @@ template <class Emitter> class VariableScope {
524524
this->addLocal(Local);
525525
}
526526

527-
virtual void emitDestruction() {}
528527
virtual bool emitDestructors(const Expr *E = nullptr) { return true; }
529528
virtual bool destroyLocals(const Expr *E = nullptr) { return true; }
530529
VariableScope *getParent() const { return Parent; }
@@ -555,15 +554,6 @@ template <class Emitter> class LocalScope : public VariableScope<Emitter> {
555554
removeStoredOpaqueValues();
556555
}
557556

558-
/// Overriden to support explicit destruction.
559-
void emitDestruction() override {
560-
if (!Idx)
561-
return;
562-
563-
this->emitDestructors();
564-
this->Ctx->emitDestroy(*Idx, SourceInfo{});
565-
}
566-
567557
/// Explicit destruction of local variables.
568558
bool destroyLocals(const Expr *E = nullptr) override {
569559
if (!Idx)

0 commit comments

Comments
 (0)