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

lib/Analysis/CFG.cpp

index a317e0452cf48d4936a45eb4c17e3df6a43d5218..eab7da7e83709af094f4c69abb7ca61fea72d524 100644 (file)
@@ -888,6 +888,19 @@ CFGBlock* CFGBuilder::VisitForStmt(ForStmt* F) {
   if (Stmt* C = F->getCond()) {
     Block = ExitConditionBlock;
     EntryConditionBlock = addStmt(C);
+    assert(Block == EntryConditionBlock);
+
+    // If this block contains a condition variable, add both the condition
+    // variable and initializer to the CFG.
+    if (VarDecl *VD = F->getConditionVariable()) {
+      if (Expr *Init = VD->getInit()) {
+        autoCreateBlock();
+        AppendStmt(Block, F, AddStmtChoice::AlwaysAdd);
+        EntryConditionBlock = addStmt(Init);
+        assert(Block == EntryConditionBlock);
+      }
+    }
+    
     if (Block) {
       if (!FinishBlock(EntryConditionBlock))
         return 0;