}
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;
}
}
continue;
}
+
+ // Specially handle macro-expanded code.
+ if (S->getLocStart().isMacroID()) {
+ count += clang::reachable_code::ScanReachableFromBlock(Block, Reachable);
+ continue;
+ }
if (isDeadCodeRoot(Block)) {
reportDeadCode(S, CB);
}
}
+// 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
+}
+
+