diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-12-24 01:34:10 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-12-24 01:34:10 +0000 |
commit | 4ec010a6ccf4db2ab2ef9e68942642d50f7f193c (patch) | |
tree | b7825fe3fd7c02195070528c22cd1ad37cbb7441 /lib/Analysis/CFG.cpp | |
parent | c8f76f557c4839c8e5f142ac4681ad010e07c855 (diff) |
CFG tweak: in a WhileStmt, the condition variable initializer is evaluated every time the condition is checked.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@92111 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/CFG.cpp')
-rw-r--r-- | lib/Analysis/CFG.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index fcdc95ec53..a317e0452c 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -1130,6 +1130,18 @@ CFGBlock* CFGBuilder::VisitWhileStmt(WhileStmt* W) { 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 = W->getConditionVariable()) { + if (Expr *Init = VD->getInit()) { + autoCreateBlock(); + AppendStmt(Block, W, AddStmtChoice::AlwaysAdd); + EntryConditionBlock = addStmt(Init); + assert(Block == EntryConditionBlock); + } + } + if (Block) { if (!FinishBlock(EntryConditionBlock)) return 0; @@ -1188,21 +1200,8 @@ CFGBlock* CFGBuilder::VisitWhileStmt(WhileStmt* W) { // to this block. NULL out Block to force lazy creation of another block. Block = NULL; - // Set Succ to be the condition block, which is the dominating block - // for the loop. + // Return the condition block, which is the dominating block for the loop. Succ = EntryConditionBlock; - - // Finally, if the WhileStmt contains a condition variable, add both the - // WhileStmt and the condition variable initialization to the CFG. - if (VarDecl *VD = W->getConditionVariable()) { - if (Expr *Init = VD->getInit()) { - autoCreateBlock(); - AppendStmt(Block, W, AddStmtChoice::AlwaysAdd); - Succ = addStmt(Init); - return Succ; - } - } - return EntryConditionBlock; } |