summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/CFG.cpp
diff options
context:
space:
mode:
authorZhongxing Xu <xuzhongxing@gmail.com>2010-09-06 07:04:06 +0000
committerZhongxing Xu <xuzhongxing@gmail.com>2010-09-06 07:04:06 +0000
commitb1e10aa67065ebc067ab190382a950b51553ac54 (patch)
tree2130f7a8435994b647d1e52e1cbace5da16b9197 /clang/lib/Analysis/CFG.cpp
parent963debc1097cb7a9c38a2694d36f2a3f6ab67639 (diff)
downloadbcm5719-llvm-b1e10aa67065ebc067ab190382a950b51553ac54.tar.gz
bcm5719-llvm-b1e10aa67065ebc067ab190382a950b51553ac54.zip
Simplify CFG construction: bail out early when we have a bad CFG.
llvm-svn: 113148
Diffstat (limited to 'clang/lib/Analysis/CFG.cpp')
-rw-r--r--clang/lib/Analysis/CFG.cpp68
1 files changed, 32 insertions, 36 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index c97b9165bca..56dbf347484 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/lib/Analysis/CFG.cpp
@@ -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
OpenPOWER on IntegriCloud