]> granicus.if.org Git - clang/commitdiff
Simplify CFG construction: bail out early when we have a bad CFG.
authorZhongxing Xu <xuzhongxing@gmail.com>
Mon, 6 Sep 2010 07:04:06 +0000 (07:04 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Mon, 6 Sep 2010 07:04:06 +0000 (07:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113148 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFG.cpp

index c97b9165bca225c826fadb0d02f532c262134f84..56dbf347484122e99b534cad41ae29061ab6574f 100644 (file)
@@ -272,58 +272,54 @@ CFG* CFGBuilder::buildCFG(const Decl *D, Stmt* Statement, ASTContext* C,
   Block = NULL;  // the EXIT block is empty.  Create all other blocks lazily.
 
   // Visit the statements and create the CFG.
-  CFGBlock* B = addStmt(Statement);
+  CFGBlock *B = addStmt(Statement);
+
+  if (badCFG)
+    return NULL;
+
+  if (B)
+    Succ = B;
 
   if (const CXXConstructorDecl *CD = dyn_cast_or_null<CXXConstructorDecl>(D)) {
     // FIXME: Add code for base initializers and member initializers.
     (void)CD;
   }
-  if (!B)
-    B = Succ;
 
-  if (B) {
-    // Finalize the last constructed block.  This usually involves reversing the
-    // order of the statements in the block.
-    if (Block) FinishBlock(B);
+  // Backpatch the gotos whose label -> block mappings we didn't know when we
+  // encountered them.
+  for (BackpatchBlocksTy::iterator I = BackpatchBlocks.begin(),
+                                   E = BackpatchBlocks.end(); I != E; ++I ) {
 
-    // Backpatch the gotos whose label -> block mappings we didn't know when we
-    // encountered them.
-    for (BackpatchBlocksTy::iterator I = BackpatchBlocks.begin(),
-         E = BackpatchBlocks.end(); I != E; ++I ) {
+    CFGBlock* B = *I;
+    GotoStmt* G = cast<GotoStmt>(B->getTerminator());
+    LabelMapTy::iterator LI = LabelMap.find(G->getLabel());
 
-      CFGBlock* B = *I;
-      GotoStmt* G = cast<GotoStmt>(B->getTerminator());
-      LabelMapTy::iterator LI = LabelMap.find(G->getLabel());
+    // If there is no target for the goto, then we are looking at an
+    // incomplete AST.  Handle this by not registering a successor.
+    if (LI == LabelMap.end()) continue;
 
-      // If there is no target for the goto, then we are looking at an
-      // incomplete AST.  Handle this by not registering a successor.
-      if (LI == LabelMap.end()) continue;
+    AddSuccessor(B, LI->second);
+  }
 
+  // Add successors to the Indirect Goto Dispatch block (if we have one).
+  if (CFGBlock* B = cfg->getIndirectGotoBlock())
+    for (LabelSetTy::iterator I = AddressTakenLabels.begin(),
+                              E = AddressTakenLabels.end(); I != E; ++I ) {
+      
+      // Lookup the target block.
+      LabelMapTy::iterator LI = LabelMap.find(*I);
+
+      // If there is no target block that contains label, then we are looking
+      // at an incomplete AST.  Handle this by not registering a successor.
+      if (LI == LabelMap.end()) continue;
+      
       AddSuccessor(B, LI->second);
     }
 
-    // Add successors to the Indirect Goto Dispatch block (if we have one).
-    if (CFGBlock* B = cfg->getIndirectGotoBlock())
-      for (LabelSetTy::iterator I = AddressTakenLabels.begin(),
-           E = AddressTakenLabels.end(); I != E; ++I ) {
-
-        // Lookup the target block.
-        LabelMapTy::iterator LI = LabelMap.find(*I);
-
-        // If there is no target block that contains label, then we are looking
-        // at an incomplete AST.  Handle this by not registering a successor.
-        if (LI == LabelMap.end()) continue;
-
-        AddSuccessor(B, LI->second);
-      }
-
-    Succ = B;
-  }
-
   // Create an empty entry block that has no predecessors.
   cfg->setEntry(createBlock());
 
-  return badCFG ? NULL : cfg.take();
+  return cfg.take();
 }
 
 /// createBlock - Used to lazily create blocks that are connected