summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
diff options
context:
space:
mode:
authorKristof Umann <dkszelethus@gmail.com>2019-03-14 16:10:29 +0000
committerKristof Umann <dkszelethus@gmail.com>2019-03-14 16:10:29 +0000
commit4962816e7242b9cec7a1a1157e4efaac75a6120a (patch)
tree2ddff6e82f79a0a6ef6901f2058909cad53bf67c /clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
parentac093d61c468b96f82d719f75e4dca8eab1e85cb (diff)
downloadbcm5719-llvm-4962816e7242b9cec7a1a1157e4efaac75a6120a.tar.gz
bcm5719-llvm-4962816e7242b9cec7a1a1157e4efaac75a6120a.zip
[analyzer] Fix an assertation failure for invalid sourcelocation, add a new debug checker
For a rather short code snippet, if debug.ReportStmts (added in this patch) was enabled, a bug reporter visitor crashed: struct h { operator int(); }; int k() { return h(); } Ultimately, this originated from PathDiagnosticLocation::createMemberLoc, as it didn't handle the case where it's MemberExpr typed parameter returned and invalid SourceLocation for MemberExpr::getMemberLoc. The solution was to find any related valid SourceLocaion, and Stmt::getBeginLoc happens to be just that. Differential Revision: https://reviews.llvm.org/D58777 llvm-svn: 356161
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp b/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
index 50715f5721c..63215e6bd3b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/DebugCheckers.cpp
@@ -266,3 +266,34 @@ void ento::registerExplodedGraphViewer(CheckerManager &mgr) {
bool ento::shouldRegisterExplodedGraphViewer(const LangOptions &LO) {
return true;
}
+
+//===----------------------------------------------------------------------===//
+// Emits a report for every Stmt that the analyzer visits.
+//===----------------------------------------------------------------------===//
+
+namespace {
+
+class ReportStmts : public Checker<check::PreStmt<Stmt>> {
+ BuiltinBug BT_stmtLoc{this, "Statement"};
+
+public:
+ void checkPreStmt(const Stmt *S, CheckerContext &C) const {
+ ExplodedNode *Node = C.generateNonFatalErrorNode();
+ if (!Node)
+ return;
+
+ auto Report = llvm::make_unique<BugReport>(BT_stmtLoc, "Statement", Node);
+
+ C.emitReport(std::move(Report));
+ }
+};
+
+} // end of anonymous namespace
+
+void ento::registerReportStmts(CheckerManager &mgr) {
+ mgr.registerChecker<ReportStmts>();
+}
+
+bool ento::shouldRegisterReportStmts(const LangOptions &LO) {
+ return true;
+}
OpenPOWER on IntegriCloud