aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/BugReporter.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-07-22 22:35:28 +0000
committerTed Kremenek <kremenek@apple.com>2009-07-22 22:35:28 +0000
commit5f85e17df3f5b0a8021443f2b590daecfb2cbd17 (patch)
tree27f50e167a2cf236ee16a7aadc89b330a62389a1 /lib/Analysis/BugReporter.cpp
parentde99a45c1295ec8e2eea20d35906178ff10722b5 (diff)
Refactor 'PostStmt' and 'PreStmt' to subclass a common parent 'StmtPoint'.
Educate GRExprEngine::VisitGraph() about 'PreStmt'. Mark the constructor of 'PostStmt' to be explicit, preventing implicit conversions and the selection of the wrong 'generateNode' method in GRStmtNodeBuilder. Constify a bunch of arguments, which falls out of the changes to ProgramPoint. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76809 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/BugReporter.cpp')
-rw-r--r--lib/Analysis/BugReporter.cpp49
1 files changed, 26 insertions, 23 deletions
diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp
index a691bb67aa..43e1e6c8bc 100644
--- a/lib/Analysis/BugReporter.cpp
+++ b/lib/Analysis/BugReporter.cpp
@@ -40,7 +40,7 @@ BugReporterContext::~BugReporterContext() {
// Helper routines for walking the ExplodedGraph and fetching statements.
//===----------------------------------------------------------------------===//
-static inline Stmt* GetStmt(ProgramPoint P) {
+static inline const Stmt* GetStmt(ProgramPoint P) {
if (const PostStmt* PS = dyn_cast<PostStmt>(&P))
return PS->getStmt();
else if (const BlockEdge* BE = dyn_cast<BlockEdge>(&P))
@@ -59,17 +59,17 @@ GetSuccessorNode(const ExplodedNode<GRState>* N) {
return N->succ_empty() ? NULL : *(N->succ_begin());
}
-static Stmt* GetPreviousStmt(const ExplodedNode<GRState>* N) {
+static const Stmt* GetPreviousStmt(const ExplodedNode<GRState>* N) {
for (N = GetPredecessorNode(N); N; N = GetPredecessorNode(N))
- if (Stmt *S = GetStmt(N->getLocation()))
+ if (const Stmt *S = GetStmt(N->getLocation()))
return S;
return 0;
}
-static Stmt* GetNextStmt(const ExplodedNode<GRState>* N) {
+static const Stmt* GetNextStmt(const ExplodedNode<GRState>* N) {
for (N = GetSuccessorNode(N); N; N = GetSuccessorNode(N))
- if (Stmt *S = GetStmt(N->getLocation())) {
+ if (const Stmt *S = GetStmt(N->getLocation())) {
// Check if the statement is '?' or '&&'/'||'. These are "merges",
// not actual statement points.
switch (S->getStmtClass()) {
@@ -90,15 +90,17 @@ static Stmt* GetNextStmt(const ExplodedNode<GRState>* N) {
return 0;
}
-static inline Stmt* GetCurrentOrPreviousStmt(const ExplodedNode<GRState>* N) {
- if (Stmt *S = GetStmt(N->getLocation()))
+static inline const Stmt*
+GetCurrentOrPreviousStmt(const ExplodedNode<GRState>* N) {
+ if (const Stmt *S = GetStmt(N->getLocation()))
return S;
return GetPreviousStmt(N);
}
-static inline Stmt* GetCurrentOrNextStmt(const ExplodedNode<GRState>* N) {
- if (Stmt *S = GetStmt(N->getLocation()))
+static inline const Stmt*
+GetCurrentOrNextStmt(const ExplodedNode<GRState>* N) {
+ if (const Stmt *S = GetStmt(N->getLocation()))
return S;
return GetNextStmt(N);
@@ -179,7 +181,7 @@ public:
PathDiagnosticLocation
PathDiagnosticBuilder::ExecutionContinues(const ExplodedNode<GRState>* N) {
- if (Stmt *S = GetNextStmt(N))
+ if (const Stmt *S = GetNextStmt(N))
return PathDiagnosticLocation(S, getSourceManager());
return FullSourceLoc(getCodeDecl().getBodyRBrace(), getSourceManager());
@@ -330,7 +332,7 @@ GetMostRecentVarDeclBinding(const ExplodedNode<GRState>* N,
if (!isa<PostStmt>(P))
continue;
- DeclRefExpr* DR = dyn_cast<DeclRefExpr>(cast<PostStmt>(P).getStmt());
+ const DeclRefExpr* DR = dyn_cast<DeclRefExpr>(cast<PostStmt>(P).getStmt());
if (!DR)
continue;
@@ -340,7 +342,7 @@ GetMostRecentVarDeclBinding(const ExplodedNode<GRState>* N,
if (X != Y)
continue;
- VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl());
+ const VarDecl* VD = dyn_cast<VarDecl>(DR->getDecl());
if (!VD)
continue;
@@ -457,13 +459,13 @@ class VISIBILITY_HIDDEN ScanNotableSymbols
llvm::SmallSet<SymbolRef, 10> AlreadyProcessed;
const ExplodedNode<GRState>* N;
- Stmt* S;
+ const Stmt* S;
GRBugReporter& BR;
PathDiagnostic& PD;
public:
- ScanNotableSymbols(const ExplodedNode<GRState>* n, Stmt* s, GRBugReporter& br,
- PathDiagnostic& pd)
+ ScanNotableSymbols(const ExplodedNode<GRState>* n, const Stmt* s,
+ GRBugReporter& br, PathDiagnostic& pd)
: N(n), S(s), BR(br), PD(pd) {}
bool HandleBinding(StoreManager& SMgr, Store store,
@@ -523,7 +525,7 @@ static void GenerateMinimalPathDiagnostic(PathDiagnostic& PD,
case Stmt::GotoStmtClass:
case Stmt::IndirectGotoStmtClass: {
- Stmt* S = GetNextStmt(N);
+ const Stmt* S = GetNextStmt(N);
if (!S)
continue;
@@ -1199,14 +1201,15 @@ void BugType::FlushReports(BugReporter &BR) {}
BugReport::~BugReport() {}
RangedBugReport::~RangedBugReport() {}
-Stmt* BugReport::getStmt(BugReporter& BR) const {
+const Stmt* BugReport::getStmt(BugReporter& BR) const {
ProgramPoint ProgP = EndNode->getLocation();
- Stmt *S = NULL;
+ const Stmt *S = NULL;
if (BlockEntrance* BE = dyn_cast<BlockEntrance>(&ProgP)) {
if (BE->getBlock() == &BR.getCFG()->getExit()) S = GetPreviousStmt(EndNode);
}
- if (!S) S = GetStmt(ProgP);
+ if (!S)
+ S = GetStmt(ProgP);
return S;
}
@@ -1215,7 +1218,7 @@ PathDiagnosticPiece*
BugReport::getEndPath(BugReporterContext& BRC,
const ExplodedNode<GRState>* EndPathNode) {
- Stmt* S = getStmt(BRC.getBugReporter());
+ const Stmt* S = getStmt(BRC.getBugReporter());
if (!S)
return NULL;
@@ -1238,7 +1241,7 @@ BugReport::getEndPath(BugReporterContext& BRC,
void BugReport::getRanges(BugReporter& BR, const SourceRange*& beg,
const SourceRange*& end) {
- if (Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) {
+ if (const Expr* E = dyn_cast_or_null<Expr>(getStmt(BR))) {
R = E->getSourceRange();
assert(R.isValid());
beg = &R;
@@ -1250,9 +1253,9 @@ void BugReport::getRanges(BugReporter& BR, const SourceRange*& beg,
SourceLocation BugReport::getLocation() const {
if (EndNode)
- if (Stmt* S = GetCurrentOrPreviousStmt(EndNode)) {
+ if (const Stmt* S = GetCurrentOrPreviousStmt(EndNode)) {
// For member expressions, return the location of the '.' or '->'.
- if (MemberExpr* ME = dyn_cast<MemberExpr>(S))
+ if (const MemberExpr* ME = dyn_cast<MemberExpr>(S))
return ME->getMemberLoc();
return S->getLocStart();