[cfe-commits] r49884 - in /cfe/trunk: include/clang/Analysis/PathSensitive/BugReporter.h lib/Analysis/BasicObjCFoundationChecks.cpp lib/Analysis/BugReporter.cpp lib/Analysis/CFRefCount.cpp lib/Analysis/GRSimpleVals.cpp
Ted Kremenek
kremenek at apple.com
Thu Apr 17 18:56:39 PDT 2008
Author: kremenek
Date: Thu Apr 17 20:56:37 2008
New Revision: 49884
URL: http://llvm.org/viewvc/llvm-project?rev=49884&view=rev
Log:
Simplified internal logic of BugReporter, consolidating EmitWarning and
EmitPathWarning into one method. We now properly handle emitting warnings
without a PathDiagnosticClient when the warning does not involve a particular
statement.
Modified:
cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp
cfe/trunk/lib/Analysis/BugReporter.cpp
cfe/trunk/lib/Analysis/CFRefCount.cpp
cfe/trunk/lib/Analysis/GRSimpleVals.cpp
Modified: cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h?rev=49884&r1=49883&r2=49884&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Thu Apr 17 20:56:37 2008
@@ -127,10 +127,8 @@
CFG& getCFG() { return getGraph().getCFG(); }
- void EmitPathWarning(BugReport& R);
-
void EmitWarning(BugReport& R);
-
+
void clearCache() { CachedErrors.clear(); }
bool IsCached(ExplodedNode<ValueState>* N);
Modified: cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp?rev=49884&r1=49883&r2=49884&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp Thu Apr 17 20:56:37 2008
@@ -190,7 +190,7 @@
void BasicObjCFoundationChecks::EmitWarnings(BugReporter& BR) {
for (ErrorsTy::iterator I=Errors.begin(), E=Errors.end(); I!=E; ++I)
- BR.EmitPathWarning(**I);
+ BR.EmitWarning(**I);
}
bool BasicObjCFoundationChecks::CheckNilArg(NodeTy* N, unsigned Arg) {
Modified: cfe/trunk/lib/Analysis/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BugReporter.cpp?rev=49884&r1=49883&r2=49884&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Thu Apr 17 20:56:37 2008
@@ -142,8 +142,10 @@
void BugReporter::GeneratePathDiagnostic(PathDiagnostic& PD,
BugReport& R) {
- ExplodedNode<ValueState>* N = R.getEndNode();
- assert (N && "Path diagnostic requires a ExplodedNode.");
+ ExplodedNode<ValueState>* N = R.getEndNode();
+
+ if (!N)
+ return;
llvm::OwningPtr<ExplodedGraph<ValueState> > GTrim(getGraph().Trim(&N, &N+1));
@@ -371,55 +373,51 @@
return false;
}
-void BugReporter::EmitPathWarning(BugReport& R) {
-
- ExplodedNode<ValueState>* N = R.getEndNode();
-
- if (!PD || !N) {
- EmitWarning(R);
- return;
- }
-
- if (IsCached(N))
+void BugReporter::EmitWarning(BugReport& R) {
+
+ if (IsCached(R.getEndNode()))
return;
-
+
PathDiagnostic D(R.getName());
GeneratePathDiagnostic(D, R);
+
+ // Emit a full diagnostic for the path if we have a PathDiagnosticClient.
- if (!D.empty())
+ if (PD && !D.empty()) {
PD->HandlePathDiagnostic(D);
-}
-
-void BugReporter::EmitWarning(BugReport& R) {
-
- ExplodedNode<ValueState>* N = R.getEndNode();
+ return;
+ }
- if (N && IsCached(N))
- return;
+ // We don't have a PathDiagnosticClient, but we can still emit a single
+ // line diagnostic. Determine the location.
- FullSourceLoc L = R.getLocation(Ctx.getSourceManager());
+ FullSourceLoc L = D.empty() ? R.getLocation(Ctx.getSourceManager())
+ : D.back()->getLocation();
- const SourceRange *Beg, *End;
- R.getRanges(Beg, End);
- if (!PD) {
+ // Determine the range.
- std::ostringstream os;
- os << "[CHECKER] " << R.getDescription();
-
- unsigned ErrorDiag = Diag.getCustomDiagID(Diagnostic::Warning,
- os.str().c_str());
-
- Diag.Report(L, ErrorDiag, NULL, 0, Beg, End - Beg);
- }
- else {
- PathDiagnostic D(R.getName());
- PathDiagnosticPiece* piece = new PathDiagnosticPiece(L, R.getDescription());
-
- for ( ; Beg != End; ++Beg)
- piece->addRange(*Beg);
-
- D.push_back(piece);
- PD->HandlePathDiagnostic(D);
+ const SourceRange *Beg, *End;
+
+ if (!D.empty()) {
+ Beg = D.back()->ranges_begin();
+ End = D.back()->ranges_end();
}
+ else
+ R.getRanges(Beg, End);
+
+ // Compute the message.
+
+ std::ostringstream os;
+ os << "[CHECKER] ";
+
+ if (D.empty())
+ os << R.getDescription();
+ else
+ os << D.back()->getString();
+
+ unsigned ErrorDiag = Diag.getCustomDiagID(Diagnostic::Warning,
+ os.str().c_str());
+
+ Diag.Report(L, ErrorDiag, NULL, 0, Beg, End - Beg);
}
Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=49884&r1=49883&r2=49884&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Thu Apr 17 20:56:37 2008
@@ -1281,7 +1281,7 @@
RangedBugReport report(*this, I->first);
report.addRange(I->second->getSourceRange());
- BR.EmitPathWarning(report);
+ BR.EmitWarning(report);
}
}
@@ -1292,7 +1292,7 @@
RangedBugReport report(*this, I->first);
report.addRange(I->second->getSourceRange());
- BR.EmitPathWarning(report);
+ BR.EmitWarning(report);
}
}
@@ -1303,7 +1303,7 @@
E = TF.leaks_end(); I != E; ++I) {
BugReport report(*this, I->second);
- BR.EmitPathWarning(report);
+ BR.EmitWarning(report);
}
}
Modified: cfe/trunk/lib/Analysis/GRSimpleVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRSimpleVals.cpp?rev=49884&r1=49883&r2=49884&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRSimpleVals.cpp (original)
+++ cfe/trunk/lib/Analysis/GRSimpleVals.cpp Thu Apr 17 20:56:37 2008
@@ -45,7 +45,7 @@
for (; I != E; ++I) {
BugReport R(D, GetNode(I));
- BR.EmitPathWarning(R);
+ BR.EmitWarning(R);
}
}
@@ -182,7 +182,7 @@
report.addRange(I->second->getSourceRange());
// Emit the warning.
- BR.EmitPathWarning(report);
+ BR.EmitWarning(report);
}
}
@@ -209,7 +209,7 @@
report.addRange(I->second->getSourceRange());
// Emit the warning.
- BR.EmitPathWarning(report);
+ BR.EmitWarning(report);
}
}
};
@@ -240,7 +240,7 @@
report.addRange(E->getSourceRange());
// Emit the warning.
- BR.EmitPathWarning(report);
+ BR.EmitWarning(report);
}
}
};
More information about the cfe-commits
mailing list