[cfe-commits] r113148 - /cfe/trunk/lib/Analysis/CFG.cpp

Zhongxing Xu xuzhongxing at gmail.com
Mon Sep 6 00:04:06 PDT 2010


Author: zhongxingxu
Date: Mon Sep  6 02:04:06 2010
New Revision: 113148

URL: http://llvm.org/viewvc/llvm-project?rev=113148&view=rev
Log:
Simplify CFG construction: bail out early when we have a bad CFG.

Modified:
    cfe/trunk/lib/Analysis/CFG.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=113148&r1=113147&r2=113148&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Mon Sep  6 02:04:06 2010
@@ -272,58 +272,54 @@
   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 ) {
-
-      CFGBlock* B = *I;
-      GotoStmt* G = cast<GotoStmt>(B->getTerminator());
-      LabelMapTy::iterator LI = LabelMap.find(G->getLabel());
+  // 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());
+
+    // 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 for the goto, then we are looking at an
-      // incomplete AST.  Handle this by not registering a successor.
+      // 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





More information about the cfe-commits mailing list