Generalize handling for unreachable code warnings to all binary operators.

llvm-svn: 93584
This commit is contained in:
Mike Stump 2010-01-15 23:33:51 +00:00
parent 3712d9e391
commit ea409449aa
2 changed files with 17 additions and 20 deletions

View File

@ -1339,24 +1339,21 @@ static SourceLocation GetUnreachableLoc(CFGBlock &b) {
switch (S->getStmtClass()) {
case Expr::BinaryOperatorClass: {
BinaryOperator *Op = cast<BinaryOperator>(S);
if (Op->getOpcode() == BinaryOperator::Comma) {
if (b.size() < 2) {
CFGBlock *n = &b;
while (1) {
if (n->getTerminator())
return n->getTerminator()->getLocStart();
if (n->succ_size() != 1)
return SourceLocation();
n = n[0].succ_begin()[0];
if (n->pred_size() != 1)
return SourceLocation();
if (!n->empty())
return n[0][0].getStmt()->getLocStart();
}
if (b.size() < 2) {
CFGBlock *n = &b;
while (1) {
if (n->getTerminator())
return n->getTerminator()->getLocStart();
if (n->succ_size() != 1)
return SourceLocation();
n = n[0].succ_begin()[0];
if (n->pred_size() != 1)
return SourceLocation();
if (!n->empty())
return n[0][0].getStmt()->getLocStart();
}
return b[1].getStmt()->getLocStart();
}
return b[1].getStmt()->getLocStart();
}
default: ;
}

View File

@ -1,4 +1,4 @@
// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code
// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code -Wno-unused-value
int halt() __attribute__((noreturn));
int live();
@ -35,9 +35,9 @@ void test2() {
dead(); // expected-warning {{will never be executed}}
case 3:
live(),
halt();
dead(); // expected-warning {{will never be executed}}
live()
+ halt();
dead(); // expected-warning {{will never be executed}}
case 4:
a4: