@@ -5104,6 +5104,16 @@ bool Compiler<Emitter>::visitCompoundStmt(const CompoundStmt *S) {
51045104 return Scope.destroyLocals ();
51055105}
51065106
5107+ template <class Emitter >
5108+ bool Compiler<Emitter>::emitDecompositionVarInit(const DecompositionDecl *DD) {
5109+ for (auto *BD : DD->bindings ())
5110+ if (auto *KD = BD->getHoldingVar ()) {
5111+ if (!this ->visitVarDecl (KD))
5112+ return false ;
5113+ }
5114+ return true ;
5115+ }
5116+
51075117template <class Emitter >
51085118bool Compiler<Emitter>::visitDeclStmt(const DeclStmt *DS) {
51095119 for (const auto *D : DS->decls ()) {
@@ -5118,12 +5128,10 @@ bool Compiler<Emitter>::visitDeclStmt(const DeclStmt *DS) {
51185128 return false ;
51195129
51205130 // Register decomposition decl holding vars.
5121- if (const auto *DD = dyn_cast<DecompositionDecl>(VD)) {
5122- for (auto *BD : DD->bindings ())
5123- if (auto *KD = BD->getHoldingVar ()) {
5124- if (!this ->visitVarDecl (KD))
5125- return false ;
5126- }
5131+ if (const auto *DD = dyn_cast<DecompositionDecl>(VD);
5132+ DD && !DD->isDecisionVariable ()) {
5133+ if (!this ->emitDecompositionVarInit (DD))
5134+ return false ;
51275135 }
51285136 }
51295137
@@ -5189,6 +5197,12 @@ template <class Emitter> bool Compiler<Emitter>::visitIfStmt(const IfStmt *IS) {
51895197 return false ;
51905198 }
51915199
5200+ if (auto *DD =
5201+ dyn_cast_if_present<DecompositionDecl>(IS->getConditionVariable ());
5202+ DD && DD->isDecisionVariable ())
5203+ if (!this ->emitDecompositionVarInit (DD))
5204+ return false ;
5205+
51925206 if (const Stmt *Else = IS->getElse ()) {
51935207 LabelTy LabelElse = this ->getLabel ();
51945208 LabelTy LabelEnd = this ->getLabel ();
@@ -5249,6 +5263,13 @@ bool Compiler<Emitter>::visitWhileStmt(const WhileStmt *S) {
52495263
52505264 if (!this ->visitBool (Cond))
52515265 return false ;
5266+
5267+ if (auto *DD =
5268+ dyn_cast_if_present<DecompositionDecl>(S->getConditionVariable ());
5269+ DD && DD->isDecisionVariable ())
5270+ if (!this ->emitDecompositionVarInit (DD))
5271+ return false ;
5272+
52525273 if (!this ->jumpFalse (EndLabel))
52535274 return false ;
52545275
@@ -5330,6 +5351,12 @@ bool Compiler<Emitter>::visitForStmt(const ForStmt *S) {
53305351 return false ;
53315352 }
53325353
5354+ if (auto *DD =
5355+ dyn_cast_if_present<DecompositionDecl>(S->getConditionVariable ());
5356+ DD && DD->isDecisionVariable ())
5357+ if (!this ->emitDecompositionVarInit (DD))
5358+ return false ;
5359+
53335360 if (Body && !this ->visitStmt (Body))
53345361 return false ;
53355362
@@ -5452,6 +5479,12 @@ bool Compiler<Emitter>::visitSwitchStmt(const SwitchStmt *S) {
54525479 if (!this ->emitSetLocal (CondT, CondVar, S))
54535480 return false ;
54545481
5482+ if (auto *DD =
5483+ dyn_cast_if_present<DecompositionDecl>(S->getConditionVariable ());
5484+ DD && DD->isDecisionVariable ())
5485+ if (!this ->emitDecompositionVarInit (DD))
5486+ return false ;
5487+
54555488 CaseMap CaseLabels;
54565489 // Create labels and comparison ops for all case statements.
54575490 for (const SwitchCase *SC = S->getSwitchCaseList (); SC;
0 commit comments