Skip to content

Commit 020147d

Browse files
committed
Actually commit the codegen fixes this time
1 parent e2b0c23 commit 020147d

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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();

clang/test/CoverageMapping/break.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,27 @@ int main(void) { // CHECK: File 0, [[@LINE]]:16 -> {{[0-9]+}}:2 = #0
3131
++cnt;
3232
}
3333
}
34+
35+
// CHECK-LABEL: break_continue_in_increment:
36+
/*
37+
52:41 -> 57:2 = #0
38+
53:10 -> 53:11 = ((#0 + #1) + #2)
39+
Branch,File 0, 53:10 -> 53:11 = #1, 0
40+
41+
53:13 -> 56:4 = #1
42+
43+
44+
45+
46+
*/
47+
48+
// CHECK: [[@LINE+6]]:20 -> [[@LINE+6]]:21 = #2
49+
// CHECK: [[@LINE+5]]:23 -> [[@LINE+5]]:28 = #3
50+
// CHECK: [[@LINE+4]]:35 -> [[@LINE+4]]:43 = (#2 - #3)
51+
// CHECK: [[@LINE+4]]:7 -> [[@LINE+4]]:8 = #2
52+
void break_continue_in_increment(int x) {
53+
while (1) {
54+
for (;; ({ if (x) break; else continue; }))
55+
;
56+
}
57+
}

0 commit comments

Comments
 (0)