]> granicus.if.org Git - clang/commitdiff
CFG: 'WhileStmts' needs an extra block to indicate the "loop back" path.
authorTed Kremenek <kremenek@apple.com>
Tue, 28 Apr 2009 03:09:44 +0000 (03:09 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 28 Apr 2009 03:09:44 +0000 (03:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70280 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/CFG.cpp

index 00f5960e11fabdad3b2e7f8fa52669acfb07cc13..ea29259f9eda6aa4f812b042585e5425180f10dd 100644 (file)
@@ -934,7 +934,7 @@ CFGBlock* CFGBuilder::VisitWhileStmt(WhileStmt* W) {
   if (Stmt* C = W->getCond()) {
     Block = ExitConditionBlock;
     EntryConditionBlock = addStmt(C);
-    assert (Block == EntryConditionBlock);
+    assert(Block == EntryConditionBlock);
     if (Block) FinishBlock(EntryConditionBlock);
   }
   
@@ -944,15 +944,20 @@ CFGBlock* CFGBuilder::VisitWhileStmt(WhileStmt* W) {
   
   // Process the loop body.
   {
-    assert (W->getBody());
+    assert(W->getBody());
 
     // Save the current values for Block, Succ, and continue and break targets
     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;
+
+    // Create an empty block to represent the transition block for looping
+    // back to the head of the loop.
+    Block = 0;
+    assert(Succ == EntryConditionBlock);
+    Succ = createBlock();
+    Succ->setLoopTarget(W);
+    ContinueTargetBlock = Succ;    
     
     // All breaks should go to the code following the loop.
     BreakTargetBlock = LoopSuccessor;