For gotos, breaks, and continues where we cannot find a target successor
block (because we are creating a CFG from an incomplete AST) we now
(gracefully) have a block ending with such statements not have any successors
instead of firing an assertion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41327 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/CFG.cpp b/AST/CFG.cpp
index 162b34c..495cfb8 100644
--- a/AST/CFG.cpp
+++ b/AST/CFG.cpp
@@ -104,8 +104,9 @@
GotoStmt* G = cast<GotoStmt>(B->getTerminator());
LabelMapTy::iterator LI = LabelMap.find(G->getLabel());
- if (LI == LabelMap.end())
- return NULL; // No matching label. Bad CFG.
+ // 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;
B->addSuccessor(LI->second);
}
@@ -511,10 +512,10 @@
Block = createBlock(false);
Block->setTerminator(C);
- // FIXME: We should gracefully handle continues without resolved targets.
- assert (ContinueTargetBlock);
+ // If there is no target for the continue, then we are looking at an
+ // incomplete AST. Handle this by not registering a successor.
+ if (ContinueTargetBlock) Block->addSuccessor(ContinueTargetBlock);
- Block->addSuccessor(ContinueTargetBlock);
return Block;
}
@@ -527,10 +528,10 @@
Block = createBlock(false);
Block->setTerminator(B);
- // FIXME: We should gracefully handle breaks without resolved targets.
- assert (BreakTargetBlock);
-
- Block->addSuccessor(BreakTargetBlock);
+ // If there is no target for the break, then we are looking at an
+ // incomplete AST. Handle this by not registering a successor.
+ if (BreakTargetBlock) Block->addSuccessor(BreakTargetBlock);
+
return Block;
}