From a7bcbde814070b71306dfbee42841d8fe3699e66 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 23 Dec 2009 04:49:01 +0000 Subject: Add CFG support for the condition variable that can appear in IfStmts in C++ mode. Add transfer function support in GRExprEngine for IfStmts with initialized condition variables. llvm-svn: 91987 --- clang/lib/Analysis/CFG.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'clang/lib/Analysis/CFG.cpp') diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index 884188acd78..8f2a5719f68 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/lib/Analysis/CFG.cpp @@ -776,7 +776,19 @@ CFGBlock* CFGBuilder::VisitIfStmt(IfStmt* I) { // Add the condition as the last statement in the new block. This may create // new blocks as the condition may contain control-flow. Any newly created // blocks will be pointed to be "Block". - return addStmt(I->getCond()); + Block = addStmt(I->getCond()); + + // Finally, if the IfStmt contains a condition variable, add both the IfStmt + // and the condition variable initialization to the CFG. + if (VarDecl *VD = I->getConditionVariable()) { + if (Expr *Init = VD->getInit()) { + autoCreateBlock(); + AppendStmt(Block, I, AddStmtChoice::AlwaysAdd); + addStmt(Init); + } + } + + return Block; } -- cgit v1.2.3