[cfe-commits] r53054 - in /cfe/trunk: Driver/AnalysisConsumer.cpp include/clang/Analysis/LocalCheckers.h include/clang/Analysis/PathSensitive/BugReporter.h lib/Analysis/DeadStores.cpp lib/Analysis/GRSimpleVals.cpp
Ted Kremenek
kremenek at apple.com
Wed Jul 2 16:16:33 PDT 2008
Author: kremenek
Date: Wed Jul 2 18:16:33 2008
New Revision: 53054
URL: http://llvm.org/viewvc/llvm-project?rev=53054&view=rev
Log:
Unify the code path for the Dead Stores checker to always use the BugReporter interface.
Modified:
cfe/trunk/Driver/AnalysisConsumer.cpp
cfe/trunk/include/clang/Analysis/LocalCheckers.h
cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
cfe/trunk/lib/Analysis/DeadStores.cpp
cfe/trunk/lib/Analysis/GRSimpleVals.cpp
Modified: cfe/trunk/Driver/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/AnalysisConsumer.cpp?rev=53054&r1=53053&r2=53054&view=diff
==============================================================================
--- cfe/trunk/Driver/AnalysisConsumer.cpp (original)
+++ cfe/trunk/Driver/AnalysisConsumer.cpp Wed Jul 2 18:16:33 2008
@@ -108,7 +108,6 @@
llvm::OwningPtr<CFG> cfg;
llvm::OwningPtr<LiveVariables> liveness;
llvm::OwningPtr<ParentMap> PM;
- llvm::OwningPtr<PathDiagnosticClient> PD;
public:
AnalysisManager(AnalysisConsumer& c, Decl* d, Stmt* b)
@@ -124,7 +123,8 @@
}
virtual ParentMap& getParentMap() {
- if (!PM) PM.reset(new ParentMap(getBody()));
+ if (!PM)
+ PM.reset(new ParentMap(getBody()));
return *PM.get();
}
@@ -145,10 +145,10 @@
}
virtual PathDiagnosticClient* getPathDiagnosticClient() {
- if (PD.get() == 0 && !C.HTMLDir.empty())
- PD.reset(CreateHTMLDiagnosticClient(C.HTMLDir, C.PP, C.PPF));
+ if (C.PD.get() == 0 && !C.HTMLDir.empty())
+ C.PD.reset(CreateHTMLDiagnosticClient(C.HTMLDir, C.PP, C.PPF));
- return PD.get();
+ return C.PD.get();
}
virtual LiveVariables& getLiveVariables() {
@@ -267,9 +267,8 @@
//===----------------------------------------------------------------------===//
static void ActionDeadStores(AnalysisManager& mgr) {
- CheckDeadStores(mgr.getCFG(), mgr.getContext(),
- mgr.getLiveVariables(), mgr.getParentMap(),
- mgr.getDiagnostic());
+ BugReporter BR(mgr);
+ CheckDeadStores(mgr.getLiveVariables(), BR);
}
static void ActionUninitVals(AnalysisManager& mgr) {
Modified: cfe/trunk/include/clang/Analysis/LocalCheckers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/LocalCheckers.h?rev=53054&r1=53053&r2=53054&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/LocalCheckers.h (original)
+++ cfe/trunk/include/clang/Analysis/LocalCheckers.h Wed Jul 2 18:16:33 2008
@@ -27,12 +27,9 @@
class LangOptions;
class ParentMap;
class LiveVariables;
+class BugReporter;
-void CheckDeadStores(CFG& cfg, ASTContext &Ctx, ParentMap& Parents,
- Diagnostic &Diags);
-
- void CheckDeadStores(CFG& cfg, ASTContext &Ctx, LiveVariables& L,
- ParentMap& Parents, Diagnostic &Diags);
+void CheckDeadStores(LiveVariables& L, BugReporter& BR);
void CheckUninitializedValues(CFG& cfg, ASTContext& Ctx, Diagnostic& Diags,
bool FullUninitTaint=false);
@@ -41,7 +38,6 @@
GRTransferFuncs* MakeCFRefCountTF(ASTContext& Ctx, bool GCEnabled,
bool StandardWarnings,
const LangOptions& lopts);
-BugType* MakeDeadStoresChecker();
} // end namespace clang
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=53054&r1=53053&r2=53054&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Wed Jul 2 18:16:33 2008
@@ -15,12 +15,15 @@
#ifndef LLVM_CLANG_ANALYSIS_BUGREPORTER
#define LLVM_CLANG_ANALYSIS_BUGREPORTER
+#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Analysis/PathSensitive/ValueState.h"
#include "clang/Analysis/PathSensitive/ExplodedGraph.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include <vector>
+#include <list>
+
namespace clang {
@@ -168,7 +171,7 @@
}
SourceManager& getSourceManager() {
- return getContext().getSourceManager();
+ return D.getSourceManager();
}
CFG& getCFG() {
@@ -223,6 +226,66 @@
}
};
+
+class DiagBugReport : public RangedBugReport {
+ std::list<std::string> Strs;
+ FullSourceLoc L;
+ const char* description;
+public:
+ DiagBugReport(const char* desc, BugType& D, FullSourceLoc l) :
+ RangedBugReport(D, NULL), L(l), description(desc) {}
+
+ virtual ~DiagBugReport() {}
+ virtual FullSourceLoc getLocation(SourceManager&) { return L; }
+
+ virtual const char* getDescription() const {
+ return description;
+ }
+
+ void addString(const std::string& s) { Strs.push_back(s); }
+
+ typedef std::list<std::string>::const_iterator str_iterator;
+ str_iterator str_begin() const { return Strs.begin(); }
+ str_iterator str_end() const { return Strs.end(); }
+};
+
+class DiagCollector : public DiagnosticClient {
+ std::list<DiagBugReport> Reports;
+ BugType& D;
+public:
+ DiagCollector(BugType& d) : D(d) {}
+
+ virtual ~DiagCollector() {}
+
+ virtual void HandleDiagnostic(Diagnostic &Diags,
+ Diagnostic::Level DiagLevel,
+ FullSourceLoc Pos,
+ diag::kind ID,
+ const std::string *Strs,
+ unsigned NumStrs,
+ const SourceRange *Ranges,
+ unsigned NumRanges) {
+
+ // FIXME: Use a map from diag::kind to BugType, instead of having just
+ // one BugType.
+
+ Reports.push_back(DiagBugReport(Diags.getDescription(ID), D, Pos));
+ DiagBugReport& R = Reports.back();
+
+ for ( ; NumRanges ; --NumRanges, ++Ranges)
+ R.addRange(*Ranges);
+
+ for ( ; NumStrs ; --NumStrs, ++Strs)
+ R.addString(*Strs);
+ }
+
+ // Iterators.
+
+ typedef std::list<DiagBugReport>::iterator iterator;
+ iterator begin() { return Reports.begin(); }
+ iterator end() { return Reports.end(); }
+};
+
} // end clang namespace
#endif
Modified: cfe/trunk/lib/Analysis/DeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/DeadStores.cpp?rev=53054&r1=53053&r2=53054&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/DeadStores.cpp (original)
+++ cfe/trunk/lib/Analysis/DeadStores.cpp Wed Jul 2 18:16:33 2008
@@ -44,8 +44,8 @@
std::string msg = inEnclosing
? "Although the value stored to '" + name +
- "' is used in the enclosing expression, the value is never actually read"
- " from '" + name + "'"
+ "' is used in the enclosing expression, the value is never actually"
+ " read from '" + name + "'"
: "Value stored to '" + name + "' is never read";
return Diags.getCustomDiagID(Diagnostic::Warning, msg.c_str());
@@ -144,115 +144,37 @@
} // end anonymous namespace
//===----------------------------------------------------------------------===//
-// Driver function to invoke the Dead-Stores checker on a CFG.
-//===----------------------------------------------------------------------===//
-
-void clang::CheckDeadStores(CFG& cfg, ASTContext &Ctx,
- ParentMap& Parents, Diagnostic &Diags) {
- LiveVariables L(cfg);
- L.runOnCFG(cfg);
- CheckDeadStores(cfg, Ctx, L, Parents, Diags);
-}
-
-void clang::CheckDeadStores(CFG& cfg, ASTContext &Ctx, LiveVariables& L,
- ParentMap& Parents, Diagnostic &Diags) {
-
- DeadStoreObs A(Ctx, Diags, Diags.getClient(), Parents);
- L.runOnAllBlocks(cfg, &A);
-}
-
-//===----------------------------------------------------------------------===//
// BugReporter-based invocation of the Dead-Stores checker.
//===----------------------------------------------------------------------===//
namespace {
-
-class VISIBILITY_HIDDEN DiagBugReport : public RangedBugReport {
- std::list<std::string> Strs;
- FullSourceLoc L;
- const char* description;
-public:
- DiagBugReport(const char* desc, BugType& D, FullSourceLoc l) :
- RangedBugReport(D, NULL), L(l), description(desc) {}
-
- virtual ~DiagBugReport() {}
- virtual FullSourceLoc getLocation(SourceManager&) { return L; }
- virtual const char* getDescription() const {
- return description;
- }
-
- void addString(const std::string& s) { Strs.push_back(s); }
-
- typedef std::list<std::string>::const_iterator str_iterator;
- str_iterator str_begin() const { return Strs.begin(); }
- str_iterator str_end() const { return Strs.end(); }
-};
-
-class VISIBILITY_HIDDEN DiagCollector : public DiagnosticClient {
- std::list<DiagBugReport> Reports;
- BugType& D;
+class SimpleBugType : public BugTypeCacheLocation {
+ const char* name;
public:
- DiagCollector(BugType& d) : D(d) {}
-
- virtual ~DiagCollector() {}
-
- virtual void HandleDiagnostic(Diagnostic &Diags,
- Diagnostic::Level DiagLevel,
- FullSourceLoc Pos,
- diag::kind ID,
- const std::string *Strs,
- unsigned NumStrs,
- const SourceRange *Ranges,
- unsigned NumRanges) {
-
- // FIXME: Use a map from diag::kind to BugType, instead of having just
- // one BugType.
-
- Reports.push_back(DiagBugReport(Diags.getDescription(ID), D, Pos));
- DiagBugReport& R = Reports.back();
-
- for ( ; NumRanges ; --NumRanges, ++Ranges)
- R.addRange(*Ranges);
-
- for ( ; NumStrs ; --NumStrs, ++Strs)
- R.addString(*Strs);
- }
-
- // Iterators.
-
- typedef std::list<DiagBugReport>::iterator iterator;
- iterator begin() { return Reports.begin(); }
- iterator end() { return Reports.end(); }
-};
+ SimpleBugType(const char* n) : name(n) {}
-class VISIBILITY_HIDDEN DeadStoresChecker : public BugTypeCacheLocation {
-public:
virtual const char* getName() const {
- return "dead store";
- }
-
- virtual const char* getDescription() const {
- return "Value stored to variable is never subsequently read.";
- }
-
- virtual void EmitWarnings(BugReporter& BR) {
-
- // Run the dead store checker and collect the diagnostics.
- DiagCollector C(*this);
- DeadStoreObs A(BR.getContext(), BR.getDiagnostic(), C, BR.getParentMap());
-
-
- BR.getLiveVariables().runOnAllBlocks(BR.getCFG(), &A);
-
- // Emit the bug reports.
-
- for (DiagCollector::iterator I = C.begin(), E = C.end(); I != E; ++I)
- BR.EmitWarning(*I);
+ return name;
}
};
} // end anonymous namespace
-BugType* clang::MakeDeadStoresChecker() {
- return new DeadStoresChecker();
+//===----------------------------------------------------------------------===//
+// Driver function to invoke the Dead-Stores checker on a CFG.
+//===----------------------------------------------------------------------===//
+
+void clang::CheckDeadStores(LiveVariables& L, BugReporter& BR) {
+
+ SimpleBugType BT("dead store");
+ DiagCollector C(BT);
+
+ DeadStoreObs A(BR.getContext(), BR.getDiagnostic(), C, BR.getParentMap());
+ L.runOnAllBlocks(BR.getCFG(), &A);
+
+ // Emit the bug reports.
+
+ for (DiagCollector::iterator I = C.begin(), E = C.end(); I != E; ++I)
+ BR.EmitWarning(*I);
}
+
Modified: cfe/trunk/lib/Analysis/GRSimpleVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRSimpleVals.cpp?rev=53054&r1=53053&r2=53054&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/GRSimpleVals.cpp (original)
+++ cfe/trunk/lib/Analysis/GRSimpleVals.cpp Wed Jul 2 18:16:33 2008
@@ -350,9 +350,6 @@
Eng.Register(new BadMsgExprArg());
Eng.Register(new BadReceiver());
- // Flow-sensitive checks.
- Eng.Register(MakeDeadStoresChecker());
-
// Add extra checkers.
ASTContext& Ctx = Eng.getContext();
ValueStateManager* VMgr = &Eng.getStateManager();
More information about the cfe-commits
mailing list