diff options
author | Anna Zaks <ganna@apple.com> | 2011-09-20 01:38:47 +0000 |
---|---|---|
committer | Anna Zaks <ganna@apple.com> | 2011-09-20 01:38:47 +0000 |
commit | 1531bb0c69d9afff6a6434e4cadf345eb628b287 (patch) | |
tree | cb12b3eb00dd8f48093bd59ab9e6011b6f2917a3 | |
parent | eecb6a1e8b95fcdb7d1a0d92b0a0311c041440cd (diff) |
[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
-rw-r--r-- | include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h | 17 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/BugReporter.cpp | 2 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 6 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/PathDiagnostic.cpp | 23 |
4 files changed, 27 insertions, 21 deletions
diff --git a/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h b/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h index 0c21788723..1b16ec50a0 100644 --- a/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h +++ b/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h @@ -143,13 +143,18 @@ public: const SourceManager &SM); /// Create a location corresponding to the given valid ExplodedNode. - PathDiagnosticLocation(const ProgramPoint& P, const SourceManager &SMng); + static PathDiagnosticLocation create(const ProgramPoint& P, + const SourceManager &SMng); /// Create a location corresponding to the next valid ExplodedNode as end /// of path location. static PathDiagnosticLocation createEndOfPath(const ExplodedNode* N, const SourceManager &SM); + /// Convert the given location into a single kind location. + static PathDiagnosticLocation createSingleLocation( + const PathDiagnosticLocation &PDL); + bool operator==(const PathDiagnosticLocation &X) const { return K == X.K && R == X.R && S == X.S && D == X.D && LC == X.LC; } @@ -173,16 +178,6 @@ public: *this = PathDiagnosticLocation(); } - /// Specify that the object represents a single location. - void setSingleLocKind() { - if (K == SingleLocK) - return; - - SourceLocation L = asLocation(); - K = SingleLocK; - R = SourceRange(L, L); - } - void flatten(); const SourceManager& getManager() const { assert(isValid()); return *SM; } diff --git a/lib/StaticAnalyzer/Core/BugReporter.cpp b/lib/StaticAnalyzer/Core/BugReporter.cpp index a90e79118d..043f5d2b81 100644 --- a/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -881,7 +881,7 @@ class EdgeBuilder { } 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 3356ed4eac..0a38e79c3b 100644 --- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -240,7 +240,8 @@ PathDiagnosticPiece *FindLastStoreBRVisitor::VisitNode(const ExplodedNode *N, // 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 @@ TrackConstraintBRVisitor::VisitNode(const ExplodedNode *N, // 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 3c798e0fac..1faace5464 100644 --- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp @@ -156,6 +156,7 @@ PathDiagnosticLocation return PathDiagnosticLocation(getValidSourceLocation(S, LC), SM, SingleLocK); } + PathDiagnosticLocation PathDiagnosticLocation::createOperatorLoc(const BinaryOperator *BO, const SourceManager &SM) { @@ -192,15 +193,16 @@ PathDiagnosticLocation 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 @@ PathDiagnosticLocation::PathDiagnosticLocation(const ProgramPoint& P, S = PS->getStmt(); } + return PathDiagnosticLocation(S, SMng, P.getLocationContext()); + if (!S) - invalidate(); + return PathDiagnosticLocation(); } PathDiagnosticLocation @@ -223,9 +227,8 @@ PathDiagnosticLocation 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 @@ PathDiagnosticLocation 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 |