[cfe-commits] r138142 - in /cfe/trunk: include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h lib/StaticAnalyzer/Core/BugReporter.cpp lib/StaticAnalyzer/Core/CFRefCount.cpp

Anna Zaks ganna at apple.com
Fri Aug 19 16:21:56 PDT 2011


Author: zaks
Date: Fri Aug 19 18:21:56 2011
New Revision: 138142

URL: http://llvm.org/viewvc/llvm-project?rev=138142&view=rev
Log:
Static Analyzer Diagnostics: Switch CFRefCount to using the new visitor API. BugReport no longer needs to inherit from BugReporterVisitor.

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
    cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h
    cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
    cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h?rev=138142&r1=138141&r2=138142&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h Fri Aug 19 18:21:56 2011
@@ -51,7 +51,7 @@
 
 /// This class provides an interface through which checkers can create
 /// individual bug reports.
-class BugReport : public BugReporterVisitor {
+class BugReport {
 public:
   class NodeResolver {
   public:
@@ -90,27 +90,19 @@
 public:
   BugReport(BugType& bt, StringRef desc, const ExplodedNode *errornode)
     : BT(bt), Description(desc), ErrorNode(errornode),
-      Callbacks(F.getEmptyList()) {
-      addVisitor(this);
-    }
+      Callbacks(F.getEmptyList()) {}
 
   BugReport(BugType& bt, StringRef shortDesc, StringRef desc,
             const ExplodedNode *errornode)
     : BT(bt), ShortDescription(shortDesc), Description(desc),
-      ErrorNode(errornode), Callbacks(F.getEmptyList()) {
-      addVisitor(this);
-    }
+      ErrorNode(errornode), Callbacks(F.getEmptyList()) {}
 
   BugReport(BugType& bt, StringRef desc, FullSourceLoc l)
     : BT(bt), Description(desc), Location(l), ErrorNode(0),
-      Callbacks(F.getEmptyList()) {
-      addVisitor(this);
-    }
+      Callbacks(F.getEmptyList()) {}
 
   virtual ~BugReport();
 
-  virtual bool isOwnedByReporterContext() { return false; }
-
   const BugType& getBugType() const { return BT; }
   BugType& getBugType() { return BT; }
 
@@ -164,11 +156,6 @@
 	/// Iterators through the custom diagnostic visitors.
   visitor_iterator visitor_begin() { return Callbacks.begin(); }
   visitor_iterator visitor_end() { return Callbacks.end(); }
-
-  virtual PathDiagnosticPiece *VisitNode(const ExplodedNode *N,
-                                         const ExplodedNode *PrevN,
-                                         BugReporterContext &BRC,
-                                         BugReport &BR);
 };
 
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h?rev=138142&r1=138141&r2=138142&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitor.h Fri Aug 19 18:21:56 2011
@@ -42,7 +42,6 @@
                                          BugReporterContext &BRC,
                                          BugReport &BR) = 0;
 
-  virtual bool isOwnedByReporterContext() { return true; }
   virtual void Profile(llvm::FoldingSetNodeID &ID) const = 0;
 };
 

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=138142&r1=138141&r2=138142&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Fri Aug 19 18:21:56 2011
@@ -1224,9 +1224,7 @@
 
 BugReport::~BugReport() {
   for (visitor_iterator I = visitor_begin(), E = visitor_end(); I != E; ++I) {
-    if ((*I)->isOwnedByReporterContext()) {
-      delete *I;
-    }
+    delete *I;
   }
 }
 
@@ -1340,13 +1338,6 @@
   return FullSourceLoc();
 }
 
-PathDiagnosticPiece *BugReport::VisitNode(const ExplodedNode *N,
-                                          const ExplodedNode *PrevN,
-                                          BugReporterContext &BRC,
-                                          BugReport &BR) {
-  return NULL;
-}
-
 //===----------------------------------------------------------------------===//
 // Methods for BugReporter and subclasses.
 //===----------------------------------------------------------------------===//

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp?rev=138142&r1=138141&r2=138142&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp Fri Aug 19 18:21:56 2011
@@ -1959,6 +1959,26 @@
   // Bug Reports.  //
   //===---------===//
 
+  class CFRefReportVisitor : public BugReporterVisitor {
+    SymbolRef Sym;
+    const CFRefCount &TF;
+  public:
+
+    CFRefReportVisitor(SymbolRef sym, const CFRefCount &tf)
+       : Sym(sym), TF(tf) {}
+
+    void Profile(llvm::FoldingSetNodeID &ID) const {
+      static int x = 0;
+      ID.AddPointer(&x);
+      ID.AddPointer(Sym);
+    }
+
+    PathDiagnosticPiece *VisitNode(const ExplodedNode *N,
+                                   const ExplodedNode *PrevN,
+                                   BugReporterContext &BRC,
+                                   BugReport &BR);
+  };
+
   class CFRefReport : public BugReport {
   protected:
     SymbolRef Sym;
@@ -1966,11 +1986,15 @@
   public:
     CFRefReport(CFRefBug& D, const CFRefCount &tf,
                 ExplodedNode *n, SymbolRef sym)
-      : BugReport(D, D.getDescription(), n), Sym(sym), TF(tf) {}
+      : BugReport(D, D.getDescription(), n), Sym(sym), TF(tf) {
+      addVisitor(new CFRefReportVisitor(sym, tf));
+    }
 
     CFRefReport(CFRefBug& D, const CFRefCount &tf,
                 ExplodedNode *n, SymbolRef sym, StringRef endText)
-      : BugReport(D, D.getDescription(), endText, n), Sym(sym), TF(tf) {}
+      : BugReport(D, D.getDescription(), endText, n), Sym(sym), TF(tf) {
+      addVisitor(new CFRefReportVisitor(sym, tf));
+    }
 
     virtual ~CFRefReport() {}
 
@@ -1991,11 +2015,6 @@
                                     const ExplodedNode *N);
 
     std::pair<const char**,const char**> getExtraDescriptiveText();
-
-    PathDiagnosticPiece *VisitNode(const ExplodedNode *N,
-                                   const ExplodedNode *PrevN,
-                                   BugReporterContext &BRC,
-                                   BugReport &BR);
   };
 
   class CFRefLeakReport : public CFRefReport {
@@ -2060,10 +2079,10 @@
   return false;
 }
 
-PathDiagnosticPiece *CFRefReport::VisitNode(const ExplodedNode *N,
-                                            const ExplodedNode *PrevN,
-                                            BugReporterContext &BRC,
-                                            BugReport &BR) {
+PathDiagnosticPiece *CFRefReportVisitor::VisitNode(const ExplodedNode *N,
+                                                   const ExplodedNode *PrevN,
+                                                   BugReporterContext &BRC,
+                                                   BugReport &BR) {
 
   if (!isa<PostStmt>(N->getLocation()))
     return NULL;
@@ -2113,7 +2132,7 @@
     if (CurrV.isOwned()) {
       os << "+1 retain count";
 
-      if (static_cast<CFRefBug&>(getBugType()).getTF().isGCEnabled()) {
+      if (TF.isGCEnabled()) {
         assert(CurrV.getObjKind() == RetEffect::CF);
         os << ".  "
         "Core Foundation objects are not automatically garbage collected.";
@@ -2507,6 +2526,8 @@
   // FIXME: AllocBinding doesn't get populated for RegionStore yet.
   if (AllocBinding)
     os << " and stored into '" << AllocBinding->getString() << '\'';
+
+  addVisitor(new CFRefReportVisitor(sym, tf));
 }
 
 //===----------------------------------------------------------------------===//





More information about the cfe-commits mailing list