diff options
Diffstat (limited to 'lib/StaticAnalyzer')
-rw-r--r-- | lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp | 4 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/BugReporterVisitors.cpp | 36 | ||||
-rw-r--r-- | lib/StaticAnalyzer/Core/PathDiagnostic.cpp | 33 |
3 files changed, 34 insertions, 39 deletions
diff --git a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp index 5dd53024b9..ed2a8590ac 100644 --- a/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp +++ b/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp @@ -2144,13 +2144,13 @@ CFRefLeakReportVisitor::getEndPath(BugReporterContext &BRC, llvm::tie(AllocNode, FirstBinding) = GetAllocationSite(BRC.getStateManager(), EndN, Sym); - SourceManager& SMgr = BRC.getSourceManager(); + SourceManager& SM = BRC.getSourceManager(); // Compute an actual location for the leak. Sometimes a leak doesn't // occur at an actual statement (e.g., transition between blocks; end // of function) so we need to walk the graph and compute a real location. const ExplodedNode *LeakN = EndN; - PathDiagnosticLocation L = PathDiagnosticLocation::create(LeakN, SMgr); + PathDiagnosticLocation L = PathDiagnosticLocation::createEndOfPath(LeakN, SM); std::string sbuf; llvm::raw_string_ostream os(sbuf); diff --git a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp index c6fd63f3bd..baef8cc9c0 100644 --- a/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp +++ b/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp @@ -238,23 +238,11 @@ PathDiagnosticPiece *FindLastStoreBRVisitor::VisitNode(const ExplodedNode *N, return NULL; } - // FIXME: Refactor this into BugReporterContext. - const Stmt *S = 0; + // Construct a new PathDiagnosticPiece. ProgramPoint P = N->getLocation(); - - if (BlockEdge *BE = dyn_cast<BlockEdge>(&P)) { - const CFGBlock *BSrc = BE->getSrc(); - S = BSrc->getTerminatorCondition(); - } - else if (PostStmt *PS = dyn_cast<PostStmt>(&P)) { - S = PS->getStmt(); - } - - if (!S) + PathDiagnosticLocation L = PathDiagnosticLocation(P,BRC.getSourceManager()); + if (!L.isValid()) return NULL; - - // Construct a new PathDiagnosticPiece. - PathDiagnosticLocation L(S, BRC.getSourceManager(), P.getLocationContext()); return new PathDiagnosticEventPiece(L, os.str()); } @@ -298,23 +286,11 @@ TrackConstraintBRVisitor::VisitNode(const ExplodedNode *N, if (os.str().empty()) return NULL; - // FIXME: Refactor this into BugReporterContext. - const Stmt *S = 0; + // Construct a new PathDiagnosticPiece. ProgramPoint P = N->getLocation(); - - if (BlockEdge *BE = dyn_cast<BlockEdge>(&P)) { - const CFGBlock *BSrc = BE->getSrc(); - S = BSrc->getTerminatorCondition(); - } - else if (PostStmt *PS = dyn_cast<PostStmt>(&P)) { - S = PS->getStmt(); - } - - if (!S) + PathDiagnosticLocation L = PathDiagnosticLocation(P,BRC.getSourceManager()); + if (!L.isValid()) return NULL; - - // Construct a new PathDiagnosticPiece. - PathDiagnosticLocation L(S, BRC.getSourceManager(), P.getLocationContext()); return new PathDiagnosticEventPiece(L, os.str()); } diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp index 8d53b2b380..8dcb03bc15 100644 --- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp @@ -130,7 +130,31 @@ void PathDiagnosticClient::HandlePathDiagnostic(const PathDiagnostic *D) { // PathDiagnosticLocation methods. //===----------------------------------------------------------------------===// -PathDiagnosticLocation PathDiagnosticLocation::create(const ExplodedNode* N, +PathDiagnosticLocation::PathDiagnosticLocation(const LocationContext *lc, + const SourceManager &sm) + : K(RangeK), S(0), D(0), SM(&sm), LC(lc) { + SourceLocation L = LC->getDecl()->getBodyRBrace(); + R = SourceRange(L, L); +} + +PathDiagnosticLocation::PathDiagnosticLocation(const ProgramPoint& P, + const SourceManager &SMng) + : K(StmtK), S(0), D(0), SM(&SMng), LC(P.getLocationContext()) { + + if (const BlockEdge *BE = dyn_cast<BlockEdge>(&P)) { + const CFGBlock *BSrc = BE->getSrc(); + S = BSrc->getTerminatorCondition(); + } + else if (const PostStmt *PS = dyn_cast<PostStmt>(&P)) { + S = PS->getStmt(); + } + + if (!S) + invalidate(); +} + +PathDiagnosticLocation PathDiagnosticLocation::createEndOfPath( + const ExplodedNode* N, const SourceManager &SM) { assert(N && "Cannot create a location with a null node."); @@ -150,8 +174,7 @@ PathDiagnosticLocation PathDiagnosticLocation::create(const ExplodedNode* N, NI = NI->succ_empty() ? 0 : *(NI->succ_begin()); } - const Decl &D = N->getCodeDecl(); - return PathDiagnosticLocation(D.getBodyRBrace(), SM); + return PathDiagnosticLocation(N->getLocationContext(), SM); } static SourceLocation getValidSourceLocation(const Stmt* S, @@ -188,10 +211,6 @@ FullSourceLoc PathDiagnosticLocation::asLocation() const { return FullSourceLoc(D->getLocation(), const_cast<SourceManager&>(*SM)); } - if (!R.isValid()) - return FullSourceLoc(LC->getDecl()->getBodyRBrace(), - const_cast<SourceManager&>(*SM)); - return FullSourceLoc(R.getBegin(), const_cast<SourceManager&>(*SM)); } |