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 | 1ce53c43207b92096a892ae41f849b7bfa5805f2 (patch) | |
tree | 079158543f0b1303c58def626ef6377eb1a5f300 /clang/lib/Analysis | |
parent | 14ee5ead2d3559d517d97db406cd33c7dd39694d (diff) | |
download | bcm5719-llvm-1ce53c43207b92096a892ae41f849b7bfa5805f2.tar.gz bcm5719-llvm-1ce53c43207b92096a892ae41f849b7bfa5805f2.zip |
CFG tweak: in a WhileStmt, the condition variable initializer is evaluated every time the condition is checked.
llvm-svn: 92111
Diffstat (limited to 'clang/lib/Analysis')
-rw-r--r-- | clang/lib/Analysis/CFG.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp index fcdc95ec53d..a317e0452cf 100644 --- a/clang/lib/Analysis/CFG.cpp +++ b/clang/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; } |