]> granicus.if.org Git - clang/commitdiff
Fix CFG construction bug:
authorTed Kremenek <kremenek@apple.com>
Thu, 4 Sep 2008 21:48:47 +0000 (21:48 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 4 Sep 2008 21:48:47 +0000 (21:48 +0000)
- 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

lib/AST/CFG.cpp

index 0231c982f4151d57c2f2c67ddf0658436b36add8..84bf1e72a4e405f25b9be2420521c34336c456c9 100644 (file)
@@ -721,18 +721,24 @@ CFGBlock* CFGBuilder::VisitForStmt(ForStmt* F) {
     SaveAndRestore<CFGBlock*> 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.