[analyzer] Use more create methods in the PathDiagnostic, cleanup.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140130 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/StaticAnalyzer/Core/BugReporter.cpp b/lib/StaticAnalyzer/Core/BugReporter.cpp
index a90e791..043f5d2 100644
--- a/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -881,7 +881,7 @@
}
if (firstCharOnly)
- L.setSingleLocKind();
+ L = PathDiagnosticLocation::createSingleLocation(L);
return L;
}
diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
index 3356ed4..0a38e79 100644
--- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
+++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
@@ -240,7 +240,8 @@
// Construct a new PathDiagnosticPiece.
ProgramPoint P = N->getLocation();
- PathDiagnosticLocation L = PathDiagnosticLocation(P,BRC.getSourceManager());
+ PathDiagnosticLocation L =
+ PathDiagnosticLocation::create(P, BRC.getSourceManager());
if (!L.isValid())
return NULL;
return new PathDiagnosticEventPiece(L, os.str());
@@ -288,7 +289,8 @@
// Construct a new PathDiagnosticPiece.
ProgramPoint P = N->getLocation();
- PathDiagnosticLocation L = PathDiagnosticLocation(P,BRC.getSourceManager());
+ PathDiagnosticLocation L =
+ PathDiagnosticLocation::create(P, BRC.getSourceManager());
if (!L.isValid())
return NULL;
return new PathDiagnosticEventPiece(L, os.str());
diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
index 3c798e0..1faace5 100644
--- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
+++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
@@ -156,6 +156,7 @@
return PathDiagnosticLocation(getValidSourceLocation(S, LC), SM, SingleLocK);
}
+
PathDiagnosticLocation
PathDiagnosticLocation::createOperatorLoc(const BinaryOperator *BO,
const SourceManager &SM) {
@@ -192,15 +193,16 @@
PathDiagnosticLocation
PathDiagnosticLocation::createDeclEnd(const LocationContext *LC,
- const SourceManager &SM) {
+ const SourceManager &SM) {
SourceLocation L = LC->getDecl()->getBodyRBrace();
return PathDiagnosticLocation(L, SM, SingleLocK);
}
-PathDiagnosticLocation::PathDiagnosticLocation(const ProgramPoint& P,
- const SourceManager &SMng)
- : K(StmtK), S(0), D(0), SM(&SMng), LC(P.getLocationContext()) {
+PathDiagnosticLocation
+ PathDiagnosticLocation::create(const ProgramPoint& P,
+ const SourceManager &SMng) {
+ const Stmt* S = 0;
if (const BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
const CFGBlock *BSrc = BE->getSrc();
S = BSrc->getTerminatorCondition();
@@ -209,8 +211,10 @@
S = PS->getStmt();
}
+ return PathDiagnosticLocation(S, SMng, P.getLocationContext());
+
if (!S)
- invalidate();
+ return PathDiagnosticLocation();
}
PathDiagnosticLocation
@@ -223,9 +227,8 @@
while (NI) {
ProgramPoint P = NI->getLocation();
const LocationContext *LC = P.getLocationContext();
- if (const StmtPoint *PS = dyn_cast<StmtPoint>(&P)) {
+ if (const StmtPoint *PS = dyn_cast<StmtPoint>(&P))
return PathDiagnosticLocation(PS->getStmt(), SM, LC);
- }
else if (const BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
const Stmt *Term = BE->getSrc()->getTerminator();
assert(Term);
@@ -237,6 +240,12 @@
return createDeclEnd(N->getLocationContext(), SM);
}
+PathDiagnosticLocation PathDiagnosticLocation::createSingleLocation(
+ const PathDiagnosticLocation &PDL) {
+ FullSourceLoc L = PDL.asLocation();
+ return PathDiagnosticLocation(L, L.getManager(), SingleLocK);
+}
+
FullSourceLoc PathDiagnosticLocation::asLocation() const {
assert(isValid());
// Note that we want a 'switch' here so that the compiler can warn us in