From: Ted Kremenek Date: Thu, 24 Dec 2009 01:49:06 +0000 (+0000) Subject: Add CFG support for the initializer of the condition variable of a ForStmt. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=58b87feeaedce7ef09c2931a39d82e5aea189f41;p=clang Add CFG support for the initializer of the condition variable of a ForStmt. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92113 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index a317e0452c..eab7da7e83 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -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;