diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-12-24 00:39:26 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-12-24 00:39:26 +0000 |
commit | 6b501ebaf172b28d6d7e1737db27f915175ad3c8 (patch) | |
tree | 8c9f3888d55a429b2e9a6af19fd763f051889497 | |
parent | a3be0eaa5c253bbf1e4eb61b0a3a9c869b94aee9 (diff) |
Add CFG support for the initializer of the condition variable of a SwitchStmt.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92101 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Analysis/CFG.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index 023ac2b7e6..cfdee4927b 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -1425,8 +1425,19 @@ CFGBlock* CFGBuilder::VisitSwitchStmt(SwitchStmt* Terminator) { SwitchTerminatedBlock->setTerminator(Terminator); assert (Terminator->getCond() && "switch condition must be non-NULL"); Block = SwitchTerminatedBlock; - - return addStmt(Terminator->getCond()); + Block = addStmt(Terminator->getCond()); + + // Finally, if the SwitchStmt contains a condition variable, add both the + // SwitchStmt and the condition variable initialization to the CFG. + if (VarDecl *VD = Terminator->getConditionVariable()) { + if (Expr *Init = VD->getInit()) { + autoCreateBlock(); + AppendStmt(Block, Terminator, AddStmtChoice::AlwaysAdd); + addStmt(Init); + } + } + + return Block; } CFGBlock* CFGBuilder::VisitCaseStmt(CaseStmt* CS) { |