[cfe-commits] r49918 - in /cfe/trunk: include/clang/Analysis/PathSensitive/BugReporter.h lib/Analysis/BasicObjCFoundationChecks.cpp lib/Analysis/BugReporter.cpp lib/Analysis/CFRefCount.cpp lib/Analysis/DeadStores.cpp lib/Analysis/GRSimpleVals.cpp

Ted Kremenek kremenek at apple.com
Fri Apr 18 13:54:29 PDT 2008


Author: kremenek
Date: Fri Apr 18 15:54:29 2008
New Revision: 49918

URL: http://llvm.org/viewvc/llvm-project?rev=49918&view=rev
Log:
Generalize caching mechanism for bugs reports.  Now individual BugTypes
can decide the policy on how to cache related bugs.  This allows us to
properly to handle warning about multiple leaks in the same location in the
ref count checker (not yet done).

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/DeadStores.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=49918&r1=49917&r2=49918&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Fri Apr 18 15:54:29 2008
@@ -32,6 +32,7 @@
 class GRExprEngine;
 class ValueState;
 class Stmt;
+class BugReport;
   
 class BugType {
 public:
@@ -43,17 +44,29 @@
       
   virtual void EmitWarnings(BugReporter& BR) {}
   virtual void GetErrorNodes(std::vector<ExplodedNode<ValueState>*>& Nodes) {}
+  
+  virtual bool isCached(BugReport& R) = 0;
+};
+  
+class BugTypeCacheLocation : public BugType {
+  llvm::SmallPtrSet<void*,10> CachedErrors;
+public:
+  BugTypeCacheLocation() {}
+  virtual ~BugTypeCacheLocation() {}  
+  virtual bool isCached(BugReport& R);
 };
   
+  
 class BugReport {
-  const BugType& Desc;
+  BugType& Desc;
   ExplodedNode<ValueState> *N;
   
 public:
-  BugReport(const BugType& D, ExplodedNode<ValueState> *n) : Desc(D), N(n) {}
+  BugReport(BugType& D, ExplodedNode<ValueState> *n) : Desc(D), N(n) {}
   virtual ~BugReport();
   
   const BugType& getBugType() const { return Desc; }
+  BugType& getBugType() { return Desc; }
   
   ExplodedNode<ValueState>* getEndNode() const { return N; }
   
@@ -82,7 +95,7 @@
 class RangedBugReport : public BugReport {
   std::vector<SourceRange> Ranges;
 public:
-  RangedBugReport(const BugType& D, ExplodedNode<ValueState> *n)
+  RangedBugReport(BugType& D, ExplodedNode<ValueState> *n)
     : BugReport(D, n) {}
   
   virtual ~RangedBugReport();
@@ -104,7 +117,6 @@
 };
   
 class BugReporter {
-  llvm::SmallPtrSet<void*,10> CachedErrors;
   Diagnostic& Diag;
   PathDiagnosticClient* PD;
   ASTContext& Ctx;
@@ -130,10 +142,6 @@
   CFG& getCFG() { return getGraph().getCFG(); }
   
   void EmitWarning(BugReport& R);
-    
-  void clearCache() { CachedErrors.clear(); }
-  
-  bool IsCached(ExplodedNode<ValueState>* N);
   
   void GeneratePathDiagnostic(PathDiagnostic& PD, BugReport& R);
 };

Modified: cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp?rev=49918&r1=49917&r2=49918&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp Fri Apr 18 15:54:29 2008
@@ -54,7 +54,7 @@
 
 namespace {
   
-class VISIBILITY_HIDDEN NilArg : public BugType {
+class VISIBILITY_HIDDEN NilArg : public BugTypeCacheLocation {
 public:
   virtual ~NilArg() {}
   

Modified: cfe/trunk/lib/Analysis/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BugReporter.cpp?rev=49918&r1=49917&r2=49918&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Fri Apr 18 15:54:29 2008
@@ -357,12 +357,14 @@
   }
 }
 
-bool BugReporter::IsCached(ExplodedNode<ValueState>* N) {
+bool BugTypeCacheLocation::isCached(BugReport& R) {
+  
+  ExplodedNode<ValueState>* N = R.getEndNode();
   
   if (!N)
     return false;
-  
-  // HACK: Cache the location of the error.  Don't emit the same
+
+  // Cache the location of the error.  Don't emit the same
   // warning for the same error type that occurs at the same program
   // location but along a different path.
   
@@ -371,14 +373,13 @@
   if (CachedErrors.count(p))
     return true;
   
-  CachedErrors.insert(p);
-  
+  CachedErrors.insert(p);  
   return false;
 }
 
 void BugReporter::EmitWarning(BugReport& R) {
 
-  if (IsCached(R.getEndNode()))
+  if (R.getBugType().isCached(R))
     return;
 
   PathDiagnostic D(R.getName());  

Modified: cfe/trunk/lib/Analysis/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFRefCount.cpp?rev=49918&r1=49917&r2=49918&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Fri Apr 18 15:54:29 2008
@@ -1268,7 +1268,7 @@
   // Bug Descriptions. //
   //===-------------===//  
   
-  class VISIBILITY_HIDDEN CFRefBug : public BugType {
+  class VISIBILITY_HIDDEN CFRefBug : public BugTypeCacheLocation {
   protected:
     CFRefCount& TF;
     
@@ -1331,7 +1331,7 @@
   class VISIBILITY_HIDDEN CFRefReport : public RangedBugReport {
     SymbolID Sym;
   public:
-    CFRefReport(const BugType& D, ExplodedNode<ValueState> *n, SymbolID sym)
+    CFRefReport(BugType& D, ExplodedNode<ValueState> *n, SymbolID sym)
       : RangedBugReport(D, n), Sym(sym) {}
         
     virtual ~CFRefReport() {}

Modified: cfe/trunk/lib/Analysis/DeadStores.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/DeadStores.cpp?rev=49918&r1=49917&r2=49918&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/DeadStores.cpp (original)
+++ cfe/trunk/lib/Analysis/DeadStores.cpp Fri Apr 18 15:54:29 2008
@@ -109,7 +109,7 @@
   std::list<std::string> Strs;
   FullSourceLoc L;
 public:
-  DiagBugReport(const BugType& D, FullSourceLoc l) :
+  DiagBugReport(BugType& D, FullSourceLoc l) :
     RangedBugReport(D, NULL), L(l) {}
   
   virtual ~DiagBugReport() {}
@@ -124,7 +124,7 @@
   
 class VISIBILITY_HIDDEN DiagCollector : public DiagnosticClient {
   std::list<DiagBugReport> Reports;
-  const BugType& D;
+  BugType& D;
 public:
   DiagCollector(BugType& d) : D(d) {}
   
@@ -159,7 +159,7 @@
   iterator end() { return Reports.end(); }
 };
   
-class VISIBILITY_HIDDEN DeadStoresChecker : public BugType {
+class VISIBILITY_HIDDEN DeadStoresChecker : public BugTypeCacheLocation {
 public:
   virtual const char* getName() const {
     return "dead store";

Modified: cfe/trunk/lib/Analysis/GRSimpleVals.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/GRSimpleVals.cpp?rev=49918&r1=49917&r2=49918&view=diff

==============================================================================
--- cfe/trunk/lib/Analysis/GRSimpleVals.cpp (original)
+++ cfe/trunk/lib/Analysis/GRSimpleVals.cpp Fri Apr 18 15:54:29 2008
@@ -40,8 +40,7 @@
 }
 
 template <typename ITER>
-void GenericEmitWarnings(BugReporter& BR, const BugType& D,
-                         ITER I, ITER E) {
+void GenericEmitWarnings(BugReporter& BR, BugType& D, ITER I, ITER E) {
   
   for (; I != E; ++I) {
     BugReport R(D, GetNode(I));    
@@ -55,7 +54,7 @@
 
 namespace {
   
-class VISIBILITY_HIDDEN NullDeref : public BugType {
+class VISIBILITY_HIDDEN NullDeref : public BugTypeCacheLocation {
 public:
   virtual const char* getName() const {
     return "null dereference";
@@ -72,7 +71,7 @@
   }
 };
 
-class VISIBILITY_HIDDEN UndefDeref : public BugType {
+class VISIBILITY_HIDDEN UndefDeref : public BugTypeCacheLocation {
 public:
   virtual const char* getName() const {
     return "bad dereference";
@@ -89,7 +88,7 @@
   }
 };
   
-class VISIBILITY_HIDDEN UndefBranch : public BugType {
+class VISIBILITY_HIDDEN UndefBranch : public BugTypeCacheLocation {
 public:
   virtual const char* getName() const {
     return "uninitialized value";
@@ -106,7 +105,7 @@
   }
 };
   
-class VISIBILITY_HIDDEN DivZero : public BugType {
+class VISIBILITY_HIDDEN DivZero : public BugTypeCacheLocation {
 public:
   virtual const char* getName() const {
     return "divide-by-zero";
@@ -123,7 +122,7 @@
   }
 };
 
-class VISIBILITY_HIDDEN UndefResult : public BugType {
+class VISIBILITY_HIDDEN UndefResult : public BugTypeCacheLocation {
 public:
   virtual const char* getName() const {
     return "undefined result";
@@ -140,7 +139,7 @@
   }
 };
   
-class VISIBILITY_HIDDEN BadCall : public BugType {
+class VISIBILITY_HIDDEN BadCall : public BugTypeCacheLocation {
 public:
   virtual const char* getName() const {
     return "invalid function call";
@@ -158,7 +157,7 @@
 };
   
   
-class VISIBILITY_HIDDEN BadArg : public BugType {
+class VISIBILITY_HIDDEN BadArg : public BugTypeCacheLocation {
 public:
   
   virtual ~BadArg() {}
@@ -214,7 +213,7 @@
   }
 };
 
-class VISIBILITY_HIDDEN BadReceiver : public BugType {
+class VISIBILITY_HIDDEN BadReceiver : public BugTypeCacheLocation {
 public:  
   virtual const char* getName() const {
     return "bad receiver";
@@ -245,7 +244,7 @@
   }
 };
   
-class VISIBILITY_HIDDEN RetStack : public BugType {
+class VISIBILITY_HIDDEN RetStack : public BugTypeCacheLocation {
 public:
   virtual const char* getName() const {
     return "return of stack address";





More information about the cfe-commits mailing list