@@ -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 {
@@ -4752,7 +4760,9 @@ bool Compiler<Emitter>::visitBreakStmt(const BreakStmt *S) {
4752
4760
if (!BreakLabel)
4753
4761
return false ;
4754
4762
4755
- this ->emitCleanup ();
4763
+ for (VariableScope<Emitter> *C = VarScope; C != LabelVarScope;
4764
+ C = C->getParent ())
4765
+ C->emitDestruction ();
4756
4766
return this ->jump (*BreakLabel);
4757
4767
}
4758
4768
@@ -4761,7 +4771,9 @@ bool Compiler<Emitter>::visitContinueStmt(const ContinueStmt *S) {
4761
4771
if (!ContinueLabel)
4762
4772
return false ;
4763
4773
4764
- this ->emitCleanup ();
4774
+ for (VariableScope<Emitter> *C = VarScope; C != LabelVarScope;
4775
+ C = C->getParent ())
4776
+ C->emitDestruction ();
4765
4777
return this ->jump (*ContinueLabel);
4766
4778
}
4767
4779
0 commit comments