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;
// 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;
}
}
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;
}
+