Teach -Wunreachable-code about dead code caused by macro expansions. This should suppress false positives resulting from 'assert' and friends.

llvm-svn: 138576
This commit is contained in:
Ted Kremenek
2011-08-25 19:28:55 +00:00
parent 5e30972cff
commit 1b7f49c2d6
2 changed files with 20 additions and 4 deletions

View File

@@ -86,12 +86,10 @@ bool DeadCodeScan::isDeadCodeRoot(const clang::CFGBlock *Block) {
}
static bool isValidDeadStmt(const Stmt *S) {
SourceLocation Loc = S->getLocStart();
if (!(Loc.isValid() && !Loc.isMacroID()))
if (S->getLocStart().isInvalid())
return false;
if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(S)) {
if (const BinaryOperator *BO = dyn_cast<BinaryOperator>(S))
return BO->getOpcode() != BO_Comma;
}
return true;
}
@@ -144,6 +142,12 @@ unsigned DeadCodeScan::scanBackwards(const clang::CFGBlock *Start,
}
continue;
}
// Specially handle macro-expanded code.
if (S->getLocStart().isMacroID()) {
count += clang::reachable_code::ScanReachableFromBlock(Block, Reachable);
continue;
}
if (isDeadCodeRoot(Block)) {
reportDeadCode(S, CB);