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
48 changes: 24 additions & 24 deletions clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5431,39 +5431,39 @@ bool Compiler<Emitter>::visitForStmt(const ForStmt *S) {
this->fallthrough(CondLabel);
this->emitLabel(CondLabel);

{
LocalScope<Emitter> CondScope(this);
if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt())
if (!visitDeclStmt(CondDecl))
return false;

if (Cond) {
if (!this->visitBool(Cond))
return false;
if (!this->jumpFalse(EndLabel))
return false;
}

if (!this->maybeEmitDeferredVarInit(S->getConditionVariable()))
return false;

if (Body && !this->visitStmt(Body))
// Start of loop body.
LocalScope<Emitter> CondScope(this);
if (const DeclStmt *CondDecl = S->getConditionVariableDeclStmt())
if (!visitDeclStmt(CondDecl))
return false;

this->fallthrough(IncLabel);
this->emitLabel(IncLabel);
if (Inc && !this->discard(Inc))
if (Cond) {
if (!this->visitBool(Cond))
return false;

if (!CondScope.destroyLocals())
if (!this->jumpFalse(EndLabel))
return false;
}
if (!this->maybeEmitDeferredVarInit(S->getConditionVariable()))
return false;

if (Body && !this->visitStmt(Body))
return false;

this->fallthrough(IncLabel);
this->emitLabel(IncLabel);
if (Inc && !this->discard(Inc))
return false;

if (!CondScope.destroyLocals())
return false;
if (!this->jump(CondLabel))
return false;
// End of loop body.

this->fallthrough(EndLabel);
this->emitLabel(EndLabel);
return true;
// If we jumped out of the loop above, we still need to clean up the condition
// scope.
return CondScope.destroyLocals();
}

template <class Emitter>
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/AST/ByteCode/Compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,9 +531,10 @@ template <class Emitter> class LocalScope : public VariableScope<Emitter> {
if (!Idx)
return true;

// NB: We are *not* resetting Idx here as to allow multiple
// calls to destroyLocals().
bool Success = this->emitDestructors(E);
this->Ctx->emitDestroy(*Idx, E);
this->Idx = std::nullopt;
return Success;
}

Expand Down