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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user