aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/BugReporter.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2008-04-14 17:39:48 +0000
committerTed Kremenek <kremenek@apple.com>2008-04-14 17:39:48 +0000
commitd2f642b56e87493edfc3b0dab359b5e32d5f8a5e (patch)
treef291d4f32525eaccf48d60cedd2bda6d64700403 /lib/Analysis/BugReporter.cpp
parent2bf78fba7a37a42d4295999706053fdf4c9625e2 (diff)
Hooked up the dead-store checker to the BugReporter interface. Now dead-store
warnings are emitted as part of the warnings registered by GRSimpleVals. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49658 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/BugReporter.cpp')
-rw-r--r--lib/Analysis/BugReporter.cpp70
1 files changed, 39 insertions, 31 deletions
diff --git a/lib/Analysis/BugReporter.cpp b/lib/Analysis/BugReporter.cpp
index 148d2582dc..310fdc9acc 100644
--- a/lib/Analysis/BugReporter.cpp
+++ b/lib/Analysis/BugReporter.cpp
@@ -52,11 +52,13 @@ static inline Stmt* GetStmt(const CFGBlock* B) {
return (*B)[0];
}
-
-PathDiagnosticPiece*
-BugReport::getEndPath(ASTContext& Ctx, ExplodedNode<ValueState> *N) const {
+Stmt* BugReport::getStmt() const {
+ return N ? GetStmt(N->getLocation()) : NULL;
+}
- Stmt* S = GetStmt(N->getLocation());
+PathDiagnosticPiece* BugReport::getEndPath(ASTContext& Ctx) const {
+
+ Stmt* S = getStmt();
if (!S)
return NULL;
@@ -83,11 +85,24 @@ BugReport::getEndPath(ASTContext& Ctx, ExplodedNode<ValueState> *N) const {
}
void BugReport::getRanges(const SourceRange*& beg,
- const SourceRange*& end) const {
+ const SourceRange*& end) const {
beg = NULL;
end = NULL;
}
+FullSourceLoc BugReport::getLocation(SourceManager& Mgr) {
+
+ if (!N)
+ return FullSourceLoc();
+
+ Stmt* S = GetStmt(N->getLocation());
+
+ if (!S)
+ return FullSourceLoc();
+
+ return FullSourceLoc(S->getLocStart(), Mgr);
+}
+
PathDiagnosticPiece* BugReport::VisitNode(ExplodedNode<ValueState>* N,
ExplodedNode<ValueState>* PrevN,
ExplodedGraph<ValueState>& G,
@@ -96,10 +111,13 @@ PathDiagnosticPiece* BugReport::VisitNode(ExplodedNode<ValueState>* N,
}
void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD,
- BugReport& R,
- ExplodedNode<ValueState>* N) {
+ BugReport& R) {
- if (PathDiagnosticPiece* Piece = R.getEndPath(Ctx,N))
+ ExplodedNode<ValueState>* N = R.getEndNode();
+
+ assert (N && "Path diagnostic requires a ExplodedNode.");
+
+ if (PathDiagnosticPiece* Piece = R.getEndPath(Ctx))
PD.push_back(Piece);
else
return;
@@ -325,10 +343,12 @@ bool BugReporter::IsCached(ExplodedNode<ValueState>* N) {
return false;
}
-void BugReporter::EmitPathWarning(BugReport& R, ExplodedNode<ValueState>* N) {
+void BugReporter::EmitPathWarning(BugReport& R) {
+
+ ExplodedNode<ValueState>* N = R.getEndNode();
- if (!PD) {
- EmitWarning(R, N);
+ if (!PD || !N) {
+ EmitWarning(R);
return;
}
@@ -336,15 +356,17 @@ void BugReporter::EmitPathWarning(BugReport& R, ExplodedNode<ValueState>* N) {
return;
PathDiagnostic D(R.getName());
- GeneratePathDiagnostic(D, R, N);
+ GeneratePathDiagnostic(D, R);
if (!D.empty())
PD->HandlePathDiagnostic(D);
}
+void BugReporter::EmitWarning(BugReport& R) {
-void BugReporter::EmitWarning(BugReport& R, ExplodedNode<ValueState>* N) {
- if (IsCached(N))
+ ExplodedNode<ValueState>* N = R.getEndNode();
+
+ if (N && IsCached(N))
return;
std::ostringstream os;
@@ -355,23 +377,9 @@ void BugReporter::EmitWarning(BugReport& R, ExplodedNode<ValueState>* N) {
// FIXME: Add support for multiple ranges.
- Stmt* S = GetStmt(N->getLocation());
-
- if (!S)
- return;
-
+ FullSourceLoc L = R.getLocation(Ctx.getSourceManager());
+
const SourceRange *Beg, *End;
R.getRanges(Beg, End);
-
- if (Beg == End) {
- SourceRange Range = S->getSourceRange();
-
- Diag.Report(FullSourceLoc(S->getLocStart(), Ctx.getSourceManager()),
- ErrorDiag, NULL, 0, &Range, 1);
-
- }
- else
- Diag.Report(FullSourceLoc(S->getLocStart(), Ctx.getSourceManager()),
- ErrorDiag, NULL, 0, Beg, End - Beg);
-
+ Diag.Report(L, ErrorDiag, NULL, 0, Beg, End - Beg);
}