From: Ted Kremenek Date: Thu, 4 Sep 2008 21:48:47 +0000 (+0000) Subject: Fix CFG construction bug: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e933450535ab077b95e59f929a4ccb25b6f360e6;p=clang Fix CFG construction bug: - Within for loops, 'continue' should jump to a basic block containing the increment code git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55800 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/CFG.cpp b/lib/AST/CFG.cpp index 0231c982f4..84bf1e72a4 100644 --- a/lib/AST/CFG.cpp +++ b/lib/AST/CFG.cpp @@ -721,18 +721,24 @@ CFGBlock* CFGBuilder::VisitForStmt(ForStmt* F) { SaveAndRestore save_Block(Block), save_Succ(Succ), save_continue(ContinueTargetBlock), save_break(BreakTargetBlock); - - // All continues within this loop should go to the condition block - ContinueTargetBlock = EntryConditionBlock; - - // All breaks should go to the code following the loop. - BreakTargetBlock = LoopSuccessor; - + // Create a new block to contain the (bottom) of the loop body. Block = NULL; - // If we have increment code, insert it at the end of the body block. - if (Stmt* I = F->getInc()) Block = addStmt(I); + if (Stmt* I = F->getInc()) { + // Generate increment code in its own basic block. This is the target + // of continue statements. + Succ = addStmt(I); + Block = 0; + ContinueTargetBlock = Succ; + } + else { + // No increment code. Continues should go the the entry condition block. + ContinueTargetBlock = EntryConditionBlock; + } + + // All breaks should go to the code following the loop. + BreakTargetBlock = LoopSuccessor; // Now populate the body block, and in the process create new blocks // as we walk the body of the loop.