[cfe-commits] r139672 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp lib/StaticAnalyzer/Core/PathDiagnostic.cpp
Anna Zaks
ganna at apple.com
Tue Sep 13 17:25:17 PDT 2011
Author: zaks
Date: Tue Sep 13 19:25:17 2011
New Revision: 139672
URL: http://llvm.org/viewvc/llvm-project?rev=139672&view=rev
Log:
[analyzer] Refactor: Make PathDiagnosticLocation responsible for creating a valid object given an ExploadedNode (the same logic can be reused by other checkers).
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h?rev=139672&r1=139671&r2=139672&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h Tue Sep 13 19:25:17 2011
@@ -24,11 +24,14 @@
namespace clang {
class Decl;
+class LocationContext;
class SourceManager;
class Stmt;
namespace ento {
+class ExplodedNode;
+
//===----------------------------------------------------------------------===//
// High-level interface for handlers of path-sensitive diagnostics.
//===----------------------------------------------------------------------===//
@@ -96,6 +99,10 @@
PathDiagnosticLocation(const Stmt *s, const SourceManager &sm)
: K(StmtK), S(s), D(0), SM(&sm) {}
+ /// Create a location corresponding to the next valid ExplodedNode.
+ static PathDiagnosticLocation create(const ExplodedNode* N,
+ const SourceManager &SM);
+
PathDiagnosticLocation(SourceRange r, const SourceManager &sm)
: K(RangeK), R(r), S(0), D(0), SM(&sm) {}
@@ -123,8 +130,6 @@
return SM != 0;
}
- const SourceManager& getSourceManager() const { assert(isValid());return *SM;}
-
FullSourceLoc asLocation() const;
PathDiagnosticRange asRange() const;
const Stmt *asStmt() const { assert(isValid()); return S; }
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp?rev=139672&r1=139671&r2=139672&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker.cpp Tue Sep 13 19:25:17 2011
@@ -2148,29 +2148,7 @@
// 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;
-
- while (LeakN) {
- ProgramPoint P = LeakN->getLocation();
-
- if (const StmtPoint *PS = dyn_cast<StmtPoint>(&P)) {
- L = PathDiagnosticLocation(PS->getStmt()->getLocStart(), SMgr);
- break;
- }
- else if (const BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
- if (const Stmt *Term = BE->getSrc()->getTerminator()) {
- L = PathDiagnosticLocation(Term->getLocStart(), SMgr);
- break;
- }
- }
-
- LeakN = LeakN->succ_empty() ? 0 : *(LeakN->succ_begin());
- }
-
- if (!L.isValid()) {
- const Decl &D = EndN->getCodeDecl();
- L = PathDiagnosticLocation(D.getBodyRBrace(), SMgr);
- }
+ PathDiagnosticLocation L = PathDiagnosticLocation::create(LeakN, SMgr);
std::string sbuf;
llvm::raw_string_ostream os(sbuf);
Modified: cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp?rev=139672&r1=139671&r2=139672&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/PathDiagnostic.cpp Tue Sep 13 19:25:17 2011
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExplodedGraph.h"
#include "clang/AST/Expr.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclObjC.h"
@@ -128,6 +129,30 @@
// PathDiagnosticLocation methods.
//===----------------------------------------------------------------------===//
+PathDiagnosticLocation PathDiagnosticLocation::create(const ExplodedNode* N,
+ const SourceManager &SM) {
+ assert(N && "Cannot create a location with a null node.");
+
+ const ExplodedNode *NI = N;
+
+ while (NI) {
+ ProgramPoint P = NI->getLocation();
+
+ if (const StmtPoint *PS = dyn_cast<StmtPoint>(&P)) {
+ return PathDiagnosticLocation(PS->getStmt(), SM);
+ }
+ else if (const BlockEdge *BE = dyn_cast<BlockEdge>(&P)) {
+ const Stmt *Term = BE->getSrc()->getTerminator();
+ assert(Term);
+ return PathDiagnosticLocation(Term, SM);
+ }
+ NI = NI->succ_empty() ? 0 : *(NI->succ_begin());
+ }
+
+ const Decl &D = N->getCodeDecl();
+ return PathDiagnosticLocation(D.getBodyRBrace(), SM);
+}
+
FullSourceLoc PathDiagnosticLocation::asLocation() const {
assert(isValid());
// Note that we want a 'switch' here so that the compiler can warn us in
More information about the cfe-commits
mailing list