@@ -114,19 +114,22 @@ template <class Emitter> class LoopScope final : public LabelScope<Emitter> {
114
114
115
115
LoopScope (Compiler<Emitter> *Ctx, LabelTy BreakLabel, LabelTy ContinueLabel)
116
116
: LabelScope<Emitter>(Ctx), OldBreakLabel(Ctx->BreakLabel),
117
- OldContinueLabel (Ctx->ContinueLabel) {
117
+ OldContinueLabel (Ctx->ContinueLabel),
118
+ OldLabelVarScope (Ctx->LabelVarScope) {
118
119
this ->Ctx ->BreakLabel = BreakLabel;
119
120
this ->Ctx ->ContinueLabel = ContinueLabel;
120
121
}
121
122
122
123
~LoopScope () {
123
124
this ->Ctx ->BreakLabel = OldBreakLabel;
124
125
this ->Ctx ->ContinueLabel = OldContinueLabel;
126
+ this ->Ctx ->LabelVarScope = OldLabelVarScope;
125
127
}
126
128
127
129
private:
128
130
OptLabelTy OldBreakLabel;
129
131
OptLabelTy OldContinueLabel;
132
+ VariableScope<Emitter> *OldLabelVarScope;
130
133
};
131
134
132
135
// Sets the context for a switch scope, mapping labels.
@@ -140,7 +143,8 @@ template <class Emitter> class SwitchScope final : public LabelScope<Emitter> {
140
143
OptLabelTy DefaultLabel)
141
144
: LabelScope<Emitter>(Ctx), OldBreakLabel(Ctx->BreakLabel),
142
145
OldDefaultLabel (this ->Ctx->DefaultLabel),
143
- OldCaseLabels (std::move(this ->Ctx->CaseLabels)) {
146
+ OldCaseLabels (std::move(this ->Ctx->CaseLabels)),
147
+ OldLabelVarScope (Ctx->LabelVarScope) {
144
148
this ->Ctx ->BreakLabel = BreakLabel;
145
149
this ->Ctx ->DefaultLabel = DefaultLabel;
146
150
this ->Ctx ->CaseLabels = std::move (CaseLabels);
@@ -150,12 +154,14 @@ template <class Emitter> class SwitchScope final : public LabelScope<Emitter> {
150
154
this ->Ctx ->BreakLabel = OldBreakLabel;
151
155
this ->Ctx ->DefaultLabel = OldDefaultLabel;
152
156
this ->Ctx ->CaseLabels = std::move (OldCaseLabels);
157
+ this ->Ctx ->LabelVarScope = OldLabelVarScope;
153
158
}
154
159
155
160
private:
156
161
OptLabelTy OldBreakLabel;
157
162
OptLabelTy OldDefaultLabel;
158
163
CaseMap OldCaseLabels;
164
+ VariableScope<Emitter> *OldLabelVarScope;
159
165
};
160
166
161
167
template <class Emitter > class StmtExprScope final {
@@ -4734,7 +4740,9 @@ bool Compiler<Emitter>::visitBreakStmt(const BreakStmt *S) {
4734
4740
if (!BreakLabel)
4735
4741
return false ;
4736
4742
4737
- this ->emitCleanup ();
4743
+ for (VariableScope<Emitter> *C = VarScope; C != LabelVarScope;
4744
+ C = C->getParent ())
4745
+ C->emitDestruction ();
4738
4746
return this ->jump (*BreakLabel);
4739
4747
}
4740
4748
@@ -4743,7 +4751,9 @@ bool Compiler<Emitter>::visitContinueStmt(const ContinueStmt *S) {
4743
4751
if (!ContinueLabel)
4744
4752
return false ;
4745
4753
4746
- this ->emitCleanup ();
4754
+ for (VariableScope<Emitter> *C = VarScope; C != LabelVarScope;
4755
+ C = C->getParent ())
4756
+ C->emitDestruction ();
4747
4757
return this ->jump (*ContinueLabel);
4748
4758
}
4749
4759
0 commit comments