@@ -1087,9 +1087,6 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
10871087 // also become the break target.
10881088 JumpDest LoopExit = getJumpDestInCurrentScope (" while.end" );
10891089
1090- // Store the blocks to use for break and continue.
1091- BreakContinueStack.push_back (BreakContinue (LoopExit, LoopHeader));
1092-
10931090 // C++ [stmt.while]p2:
10941091 // When the condition of a while statement is a declaration, the
10951092 // scope of the variable that is declared extends from its point
@@ -1158,6 +1155,9 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
11581155 << SourceRange (S.getWhileLoc (), S.getRParenLoc ());
11591156 }
11601157
1158+ // Store the blocks to use for break and continue.
1159+ BreakContinueStack.push_back (BreakContinue (LoopExit, LoopHeader));
1160+
11611161 // Emit the loop body. We have to emit this in a cleanup scope
11621162 // because it might be a singleton DeclStmt.
11631163 {
@@ -1206,8 +1206,6 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S,
12061206
12071207 uint64_t ParentCount = getCurrentProfileCount ();
12081208
1209- // Store the blocks to use for break and continue.
1210- BreakContinueStack.push_back (BreakContinue (LoopExit, LoopCond));
12111209
12121210 // Emit the body of the loop.
12131211 llvm::BasicBlock *LoopBody = createBasicBlock (" do.body" );
@@ -1220,10 +1218,13 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S,
12201218 if (CGM.shouldEmitConvergenceTokens ())
12211219 ConvergenceTokenStack.push_back (emitConvergenceLoopToken (LoopBody));
12221220
1221+ // Store the blocks to use for break and continue.
1222+ BreakContinueStack.push_back (BreakContinue (LoopExit, LoopCond));
12231223 {
12241224 RunCleanupsScope BodyScope (*this );
12251225 EmitStmt (S.getBody ());
12261226 }
1227+ BreakContinueStack.pop_back ();
12271228
12281229 EmitBlock (LoopCond.getBlock ());
12291230 // When single byte coverage mode is enabled, add a counter to loop condition.
@@ -1238,8 +1239,6 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S,
12381239 // compares unequal to 0. The condition must be a scalar type.
12391240 llvm::Value *BoolCondVal = EvaluateExprAsBool (S.getCond ());
12401241
1241- BreakContinueStack.pop_back ();
1242-
12431242 // "do {} while (0)" is common in macros, avoid extra blocks. Be sure
12441243 // to correctly handle break/continue though.
12451244 llvm::ConstantInt *C = dyn_cast<llvm::ConstantInt>(BoolCondVal);
@@ -1328,7 +1327,6 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
13281327 Continue = CondDest;
13291328 else if (!S.getConditionVariable ())
13301329 Continue = getJumpDestInCurrentScope (" for.inc" );
1331- BreakContinueStack.push_back (BreakContinue (LoopExit, Continue));
13321330
13331331 if (S.getCond ()) {
13341332 // If the for statement has a condition scope, emit the local variable
@@ -1339,7 +1337,6 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
13391337 // We have entered the condition variable's scope, so we're now able to
13401338 // jump to the continue block.
13411339 Continue = S.getInc () ? getJumpDestInCurrentScope (" for.inc" ) : CondDest;
1342- BreakContinueStack.back ().ContinueBlock = Continue;
13431340 }
13441341
13451342 // When single byte coverage mode is enabled, add a counter to loop
@@ -1381,7 +1378,6 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
13811378 EmitBlock (ExitBlock);
13821379 EmitBranchThroughCleanup (LoopExit);
13831380 }
1384-
13851381 EmitBlock (ForBody);
13861382 } else {
13871383 // Treat it as a non-zero constant. Don't even create a new block for the
@@ -1393,12 +1389,15 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
13931389 incrementProfileCounter (S.getBody ());
13941390 else
13951391 incrementProfileCounter (&S);
1392+
1393+ BreakContinueStack.push_back (BreakContinue (LoopExit, Continue));
13961394 {
13971395 // Create a separate cleanup scope for the body, in case it is not
13981396 // a compound statement.
13991397 RunCleanupsScope BodyScope (*this );
14001398 EmitStmt (S.getBody ());
14011399 }
1400+ BreakContinueStack.pop_back ();
14021401
14031402 // The last block in the loop's body (which unconditionally branches to the
14041403 // `inc` block if there is one).
@@ -1412,8 +1411,6 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
14121411 incrementProfileCounter (S.getInc ());
14131412 }
14141413
1415- BreakContinueStack.pop_back ();
1416-
14171414 ConditionScope.ForceCleanup ();
14181415
14191416 EmitStopPoint (&S);
@@ -1518,6 +1515,8 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S,
15181515 EmitStmt (S.getLoopVarStmt ());
15191516 EmitStmt (S.getBody ());
15201517 }
1518+ BreakContinueStack.pop_back ();
1519+
15211520 // The last block in the loop's body (which unconditionally branches to the
15221521 // `inc` block if there is one).
15231522 auto *FinalBodyBB = Builder.GetInsertBlock ();
@@ -1527,8 +1526,6 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S,
15271526 EmitBlock (Continue.getBlock ());
15281527 EmitStmt (S.getInc ());
15291528
1530- BreakContinueStack.pop_back ();
1531-
15321529 EmitBranch (CondBlock);
15331530
15341531 ForScope.ForceCleanup ();
0 commit comments