aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-12-24 01:34:10 +0000
committerTed Kremenek <kremenek@apple.com>2009-12-24 01:34:10 +0000
commit4ec010a6ccf4db2ab2ef9e68942642d50f7f193c (patch)
treeb7825fe3fd7c02195070528c22cd1ad37cbb7441
parentc8f76f557c4839c8e5f142ac4681ad010e07c855 (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
-rw-r--r--lib/Analysis/CFG.cpp27
-rw-r--r--test/Analysis/misc-ps-region-store.cpp19
2 files changed, 23 insertions, 23 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;
}
diff --git a/test/Analysis/misc-ps-region-store.cpp b/test/Analysis/misc-ps-region-store.cpp
index fcef0516ec..f71bb0ea38 100644
--- a/test/Analysis/misc-ps-region-store.cpp
+++ b/test/Analysis/misc-ps-region-store.cpp
@@ -61,16 +61,17 @@ int test_init_in_condition_switch() {
}
int test_init_in_condition_while() {
- int y = 1;
- while (int x = test_init_in_condition_aux()) { // no-warning
- if (!x) {
- y = 0;
+ int z = 0;
+ while (int x = ++z) { // no-warning
+ if (x == 2)
break;
- }
- }
- if (!y) {
- int *p = 0;
- *p = 0xDEADBEEF; // no-warning
}
+
+ if (z == 2)
+ return 0;
+
+ int *p = 0;
+ *p = 0xDEADBEEF; // no-warning
return 0;
}
+