@@ -1576,9 +1576,9 @@ bool Converter::VisitAttributedStmt(clang::AttributedStmt *stmt) {
15761576}
15771577
15781578bool Converter::VisitWhileStmt (clang::WhileStmt *stmt) {
1579- ScopedValue break_loop (break_switch_, false );
1579+ ScopedValue break_loop (break_label_, " " );
15801580 StrCat (" 'loop_:" );
1581- ScopedValue no_inc (curr_for_inc_, nullptr );
1581+ ScopedValue no_inc (continue_for_, false );
15821582 if (auto *cond_var = stmt->getConditionVariableDeclStmt ()) {
15831583 StrCat (keyword::kLoop );
15841584 PushBrace loop_brace (*this );
@@ -1605,7 +1605,7 @@ void Converter::ConvertConditionVariableTest(clang::DeclStmt *cond_var,
16051605}
16061606
16071607bool Converter::VisitDoStmt (clang::DoStmt *stmt) {
1608- ScopedValue break_loop (break_switch_, false );
1608+ ScopedValue break_loop (break_label_, " " );
16091609 const char *control_var = " __do_while" ;
16101610 StrCat (keyword::kLet , " mut" , control_var, token::kAssign , keyword::kTrue ,
16111611 token::kSemiColon );
@@ -1617,14 +1617,14 @@ bool Converter::VisitDoStmt(clang::DoStmt *stmt) {
16171617 {
16181618 PushBrace loop_brace (*this );
16191619 StrCat (control_var, token::kAssign , keyword::kFalse , token::kSemiColon );
1620- ScopedValue no_inc (curr_for_inc_, nullptr );
1620+ ScopedValue no_inc (continue_for_, false );
16211621 ConvertBodyStmts (stmt->getBody ());
16221622 }
16231623 return false ;
16241624}
16251625
16261626bool Converter::VisitForStmt (clang::ForStmt *stmt) {
1627- ScopedValue break_loop (break_switch_, false );
1627+ ScopedValue break_loop (break_label_, stmt-> getInc () ? " 'loop_ " : " " );
16281628 // The variables of the init statement are only visible in the for.
16291629 PushBrace scope (*this , stmt->getInit () &&
16301630 clang::isa<clang::DeclStmt>(stmt->getInit ()));
@@ -1647,7 +1647,14 @@ bool Converter::VisitForStmt(clang::ForStmt *stmt) {
16471647 ConvertConditionVariableTest (cond_var, stmt->getCond ());
16481648 }
16491649 {
1650- ScopedValue inc (curr_for_inc_, stmt->getInc ());
1650+ ScopedValue inc (continue_for_, stmt->getInc () != nullptr );
1651+ // Leaving the body, including via continue, destroys its locals before
1652+ // the increment. The condition variable stays alive through the
1653+ // increment.
1654+ if (continue_for_) {
1655+ StrCat (" 'for_body:" );
1656+ }
1657+ PushBrace body (*this , continue_for_);
16511658 ConvertBodyStmts (stmt->getBody ());
16521659 }
16531660 Convert (stmt->getInc ());
@@ -1657,7 +1664,7 @@ bool Converter::VisitForStmt(clang::ForStmt *stmt) {
16571664}
16581665
16591666bool Converter::VisitCXXForRangeStmt (clang::CXXForRangeStmt *stmt) {
1660- ScopedValue break_loop (break_switch_, false );
1667+ ScopedValue break_loop (break_label_, " " );
16611668 Convert (stmt->getInit ());
16621669 Convert (stmt->getRangeStmt ());
16631670 auto *begin =
@@ -1672,28 +1679,24 @@ bool Converter::VisitCXXForRangeStmt(clang::CXXForRangeStmt *stmt) {
16721679 ConvertFreshRValue (end->getInit ()), ' )' );
16731680 {
16741681 PushBrace brace (*this );
1675- ScopedValue no_inc (curr_for_inc_, nullptr );
1682+ ScopedValue no_inc (continue_for_, false );
16761683 Convert (stmt->getLoopVarStmt ());
16771684 ConvertBodyStmts (stmt->getBody ());
16781685 }
16791686 return false ;
16801687}
16811688
16821689bool Converter::VisitBreakStmt ([[maybe_unused]] clang::BreakStmt *stmt) {
1683- StrCat (keyword::kBreak );
1684- if (break_switch_) {
1685- StrCat (" 'switch" );
1686- }
1690+ StrCat (keyword::kBreak , break_label_);
16871691 return false ;
16881692}
16891693
16901694bool Converter::VisitContinueStmt ([[maybe_unused]] clang::ContinueStmt *stmt) {
1691- if (curr_for_inc_) {
1692- Convert (curr_for_inc_);
1693- StrCat (token::kSemiColon );
1695+ if (continue_for_) {
1696+ StrCat (keyword::kBreak , " 'for_body" );
1697+ } else {
1698+ StrCat (keyword::kContinue , " 'loop_" );
16941699 }
1695- StrCat (keyword::kContinue );
1696- StrCat (" 'loop_" );
16971700 return false ;
16981701}
16991702
@@ -4524,7 +4527,7 @@ bool Converter::VisitSwitchStmt(clang::SwitchStmt *stmt) {
45244527 return !arm.label .empty () || arm.has_fallthrough ;
45254528 });
45264529
4527- ScopedValue break_switch (break_switch_, ! needs_switch_macro);
4530+ ScopedValue break_switch (break_label_, needs_switch_macro ? " " : " 'switch " );
45284531
45294532 // The variables of the init statement and of the condition are only
45304533 // visible in the switch.
0 commit comments