Fix crash in -Wuninitialized when using switch statments whose condition is a logical operation.

llvm-svn: 131158
This commit is contained in:
Ted Kremenek 2011-05-10 22:10:35 +00:00
parent a678098f24
commit efdb7fe53b
2 changed files with 22 additions and 5 deletions

View File

@ -214,11 +214,15 @@ static BinaryOperator *getLogicalOperatorInChain(const CFGBlock *block) {
if (!b || !b->isLogicalOp())
return 0;
if (block->pred_size() == 2 &&
((block->succ_size() == 2 && block->getTerminatorCondition() == b) ||
block->size() == 1))
return b;
if (block->pred_size() == 2) {
if (block->getTerminatorCondition() == b) {
if (block->succ_size() == 2)
return b;
}
else if (block->size() == 1)
return b;
}
return 0;
}

View File

@ -339,3 +339,16 @@ int test51(void)
return a; // no-warning
}
// FIXME: This is a false positive, but it tests logical operations in switch statements.
int test52(int a, int b) {
int x; // expected-note {{variable 'x' is declared here}} expected-note {{add initialization to silence this warning}}
switch (a || b) { // expected-warning {{switch condition has boolean value}}
case 0:
x = 1;
break;
case 1:
x = 2;
break;
}
return x; // expected-warning {{variable 'x' may be uninitialized when used here}}
}