From: Ted Kremenek Date: Thu, 23 Aug 2007 17:29:58 +0000 (+0000) Subject: For gotos, breaks, and continues where we cannot find a target successor X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=989d52d469df0c202f7de82f54407066c7db2e63;p=clang 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 162b34c423..495cfb8d1e 100644 --- a/AST/CFG.cpp +++ b/AST/CFG.cpp @@ -104,8 +104,9 @@ public: GotoStmt* G = cast(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 @@ public: 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 @@ public: 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; }