summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Core/PathDiagnostic.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/Core/PathDiagnostic.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/Core/PathDiagnostic.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
index 13e3bcfad2a..cc1e7e1798f 100644
--- a/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ b/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -571,6 +571,8 @@ static SourceLocation getValidSourceLocation(const Stmt* S,
} while (!L.isValid());
}
+ // FIXME: Ironically, this assert actually fails in some cases.
+ //assert(L.isValid());
return L;
}
@@ -671,7 +673,15 @@ PathDiagnosticLocation::createConditionalColonLoc(
PathDiagnosticLocation
PathDiagnosticLocation::createMemberLoc(const MemberExpr *ME,
const SourceManager &SM) {
- return PathDiagnosticLocation(ME->getMemberLoc(), SM, SingleLocK);
+
+ assert(ME->getMemberLoc().isValid() || ME->getBeginLoc().isValid());
+
+ // In some cases, getMemberLoc isn't valid -- in this case we'll return with
+ // some other related valid SourceLocation.
+ if (ME->getMemberLoc().isValid())
+ return PathDiagnosticLocation(ME->getMemberLoc(), SM, SingleLocK);
+
+ return PathDiagnosticLocation(ME->getBeginLoc(), SM, SingleLocK);
}
PathDiagnosticLocation
OpenPOWER on IntegriCloud