forked from OSchip/llvm-project
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:
parent
5e30972cff
commit
1b7f49c2d6
|
@ -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);
|
||||
|
|
|
@ -114,3 +114,15 @@ int test_enum_cases(enum Cases C) {
|
|||
}
|
||||
}
|
||||
|
||||
// Handle unreachable code triggered by macro expansions.
|
||||
void __myassert_rtn(const char *, const char *, int, const char *) __attribute__((__noreturn__));
|
||||
|
||||
#define myassert(e) \
|
||||
(__builtin_expect(!(e), 0) ? __myassert_rtn(__func__, __FILE__, __LINE__, #e) : (void)0)
|
||||
|
||||
void test_assert() {
|
||||
myassert(0 && "unreachable");
|
||||
return; // no-warning
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue