]> granicus.if.org Git - clang/commitdiff
Add CFG support for the initializer of the condition variable of a SwitchStmt.
authorTed Kremenek <kremenek@apple.com>
Thu, 24 Dec 2009 00:39:26 +0000 (00:39 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 24 Dec 2009 00:39:26 +0000 (00:39 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92101 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFG.cpp

index 023ac2b7e6ee832015bd00ee1ce997402f512a01..cfdee4927bb1b7669e99cb48de58d0c9823033cf 100644 (file)
@@ -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) {