Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5939,8 +5939,10 @@ bool Compiler<Emitter>::visitBreakStmt(const BreakStmt *S) {
assert(TargetLabel);

for (VariableScope<Emitter> *C = this->VarScope; C != BreakScope;
C = C->getParent())
C->emitDestruction();
C = C->getParent()) {
if (!C->destroyLocals())
return false;
}

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

for (VariableScope<Emitter> *C = VarScope; C != ContinueScope;
C = C->getParent())
C->emitDestruction();
C = C->getParent()) {
if (!C->destroyLocals())
return false;
}

return this->jump(*TargetLabel);
}
Expand Down Expand Up @@ -7159,9 +7163,12 @@ bool Compiler<Emitter>::VisitDeclRefExpr(const DeclRefExpr *E) {
return this->visitDeclRef(D, E);
}

template <class Emitter> void Compiler<Emitter>::emitCleanup() {
for (VariableScope<Emitter> *C = VarScope; C; C = C->getParent())
C->emitDestruction();
template <class Emitter> bool Compiler<Emitter>::emitCleanup() {
for (VariableScope<Emitter> *C = VarScope; C; C = C->getParent()) {
if (!C->destroyLocals())
return false;
}
return true;
}

template <class Emitter>
Expand Down
12 changes: 1 addition & 11 deletions clang/lib/AST/ByteCode/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,

protected:
/// Emits scope cleanup instructions.
void emitCleanup();
bool emitCleanup();

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

virtual void emitDestruction() {}
virtual bool emitDestructors(const Expr *E = nullptr) { return true; }
virtual bool destroyLocals(const Expr *E = nullptr) { return true; }
VariableScope *getParent() const { return Parent; }
Expand Down Expand Up @@ -555,15 +554,6 @@ template <class Emitter> class LocalScope : public VariableScope<Emitter> {
removeStoredOpaqueValues();
}

/// Overriden to support explicit destruction.
void emitDestruction() override {
if (!Idx)
return;

this->emitDestructors();
this->Ctx->emitDestroy(*Idx, SourceInfo{});
}

/// Explicit destruction of local variables.
bool destroyLocals(const Expr *E = nullptr) override {
if (!Idx)
Expand Down