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