[cfe-commits] r56385 - in /cfe/trunk: include/clang/Analysis/PathDiagnostic.h include/clang/Analysis/PathSensitive/BugReporter.h lib/Analysis/BugReporter.cpp lib/Analysis/CFRefCount.cpp lib/Analysis/CheckDeadStores.cpp lib/Analysis/GRExprEngineInternalChecks.cpp lib/Driver/HTMLDiagnostics.cpp

Ted Kremenek kremenek at apple.com
Fri Sep 19 21:23:40 PDT 2008


Author: kremenek
Date: Fri Sep 19 23:23:38 2008
New Revision: 56385

URL: http://llvm.org/viewvc/llvm-project?rev=56385&view=rev
Log:
Add "category" to BugTypes, allowing bugs to be grouped.
Changed casing of many bug names.  The convention will be to have bug names (mostly) lower cased, and categories use some capitalization.

Modified:
    cfe/trunk/include/clang/Analysis/PathDiagnostic.h
    cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h
    cfe/trunk/lib/Analysis/BugReporter.cpp
    cfe/trunk/lib/Analysis/CFRefCount.cpp
    cfe/trunk/lib/Analysis/CheckDeadStores.cpp
    cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp
    cfe/trunk/lib/Driver/HTMLDiagnostics.cpp

Modified: cfe/trunk/include/clang/Analysis/PathDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/PathDiagnostic.h?rev=56385&r1=56384&r2=56385&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathDiagnostic.h (original)
+++ cfe/trunk/include/clang/Analysis/PathDiagnostic.h Fri Sep 19 23:23:38 2008
@@ -77,18 +77,22 @@
   std::list<PathDiagnosticPiece*> path;
   unsigned Size;
   std::string Desc;
+  std::string Category;
   std::vector<std::string> OtherDesc;
 
 public:  
   PathDiagnostic() : Size(0) {}
 
-  PathDiagnostic(const char* desc) : Size(0), Desc(desc) {}
+  PathDiagnostic(const char* desc, const char* category)
+    : Size(0), Desc(desc), Category(category) {}
   
-  PathDiagnostic(const std::string& desc) : Size(0), Desc(desc) {}
+  PathDiagnostic(const std::string& desc, const std::string& category)
+    : Size(0), Desc(desc), Category(category) {}
   
   ~PathDiagnostic();
 
   const std::string& getDescription() const { return Desc; }
+  const std::string& getCategory() const { return Category; }
   
   typedef std::vector<std::string>::const_iterator meta_iterator;
   meta_iterator meta_begin() const { return OtherDesc.begin(); }

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=56385&r1=56384&r2=56385&view=diff

==============================================================================
--- cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h (original)
+++ cfe/trunk/include/clang/Analysis/PathSensitive/BugReporter.h Fri Sep 19 23:23:38 2008
@@ -45,6 +45,7 @@
   
   virtual const char* getName() const = 0;
   virtual const char* getDescription() const { return getName(); }
+  virtual const char* getCategory() const { return ""; }
   
   virtual std::pair<const char**,const char**> getExtraDescriptiveText() {
     return std::pair<const char**, const char**>(0, 0);
@@ -87,6 +88,10 @@
     return getBugType().getDescription();
   }
   
+  virtual const char* getCategory() const {
+    return getBugType().getCategory();
+  }
+  
   virtual std::pair<const char**,const char**> getExtraDescriptiveText() {
     return getBugType().getExtraDescriptiveText();
   }
@@ -200,6 +205,11 @@
                        SourceLocation Loc,
                        SourceRange* RangeBeg, unsigned NumRanges);
 
+  void EmitBasicReport(const char* BugName, const char* BugCategory,
+                       const char* BugStr, SourceLocation Loc,
+                       SourceRange* RangeBeg, unsigned NumRanges);
+  
+  
   void EmitBasicReport(const char* BugName, const char* BugStr,
                        SourceLocation Loc) {
     EmitBasicReport(BugName, BugStr, Loc, 0, 0);
@@ -210,6 +220,11 @@
     EmitBasicReport(BugName, BugStr, Loc, &R, 1);
   }
   
+  void EmitBasicReport(const char* BugName, const char* Category,
+                       const char* BugStr, SourceLocation Loc, SourceRange R) {
+    EmitBasicReport(BugName, Category, BugStr, Loc, &R, 1);
+  }
+  
   static bool classof(const BugReporter* R) { return true; }
 };
   
@@ -315,13 +330,16 @@
   
 class SimpleBugType : public BugTypeCacheLocation {
   const char* name;
+  const char* category;
   const char* desc;
 public:
-  SimpleBugType(const char* n) : name(n), desc(n) {}
-  SimpleBugType(const char* n, const char* d) : name(n), desc(d) {}
+  SimpleBugType(const char* n) : name(n), category(""), desc(0) {}
+  SimpleBugType(const char* n, const char* c, const char* d)
+    : name(n), category(c), desc(d) {}
   
   virtual const char* getName() const { return name; }
-  virtual const char* getDescription() const { return desc; }
+  virtual const char* getDescription() const { return desc ? desc : name; }
+  virtual const char* getCategory() const { return category; }
 };
   
 } // end clang namespace

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

==============================================================================
--- cfe/trunk/lib/Analysis/BugReporter.cpp (original)
+++ cfe/trunk/lib/Analysis/BugReporter.cpp Fri Sep 19 23:23:38 2008
@@ -701,7 +701,8 @@
   if (R.getBugType().isCached(R))
     return;
 
-  llvm::OwningPtr<PathDiagnostic> D(new PathDiagnostic(R.getName()));
+  llvm::OwningPtr<PathDiagnostic> D(new PathDiagnostic(R.getName(),
+                                                       R.getCategory()));
   GeneratePathDiagnostic(*D.get(), R);
   
   // Get the meta data.
@@ -764,12 +765,17 @@
   }
 }
 
-void
-BugReporter::EmitBasicReport(const char* name, const char* str,
-                             SourceLocation Loc,
-                             SourceRange* RBeg, unsigned NumRanges) {
+void BugReporter::EmitBasicReport(const char* name, const char* str,
+                                  SourceLocation Loc,
+                                  SourceRange* RBeg, unsigned NumRanges) {
+  EmitBasicReport(name, "", str, Loc, RBeg, NumRanges);
+}
+  
+void BugReporter::EmitBasicReport(const char* name, const char* category,
+                                  const char* str, SourceLocation Loc,
+                                  SourceRange* RBeg, unsigned NumRanges) {
   
-  SimpleBugType BT(name);
+  SimpleBugType BT(name, category, 0);
   DiagCollector C(BT);
   Diagnostic& Diag = getDiagnostic();
   Diag.Report(&C, getContext().getFullLoc(Loc),

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

==============================================================================
--- cfe/trunk/lib/Analysis/CFRefCount.cpp (original)
+++ cfe/trunk/lib/Analysis/CFRefCount.cpp Fri Sep 19 23:23:38 2008
@@ -2020,6 +2020,10 @@
     const CFRefCount& getTF() const { return TF; }
 
     virtual bool isLeak() const { return false; }
+
+    const char* getCategory() const { 
+      return "Memory (Core Foundation/Objective-C)";
+    }
   };
   
   class VISIBILITY_HIDDEN UseAfterRelease : public CFRefBug {
@@ -2027,7 +2031,7 @@
     UseAfterRelease(CFRefCount& tf) : CFRefBug(tf) {}
     
     virtual const char* getName() const {
-      return "Use-After-Release";
+      return "use-after-release";
     }
     virtual const char* getDescription() const {
       return "Reference-counted object is used after it is released.";
@@ -2041,7 +2045,7 @@
     BadRelease(CFRefCount& tf) : CFRefBug(tf) {}
     
     virtual const char* getName() const {
-      return "Bad Release";
+      return "bad release";
     }
     virtual const char* getDescription() const {
       return "Incorrect decrement of the reference count of a "
@@ -2059,13 +2063,13 @@
     virtual const char* getName() const {
       
       if (getTF().isGCEnabled())
-        return "Memory Leak (GC)";
+        return "Leak (GC)";
       
       if (getTF().getLangOptions().getGCMode() == LangOptions::HybridGC)
-        return "Memory Leak (Hybrid MM, non-GC)";
+        return "leak (hybrid MM, non-GC)";
       
       assert (getTF().getLangOptions().getGCMode() == LangOptions::NonGC);
-      return "Memory Leak";
+      return "leak";
     }
     
     virtual const char* getDescription() const {

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

==============================================================================
--- cfe/trunk/lib/Analysis/CheckDeadStores.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckDeadStores.cpp Fri Sep 19 23:23:38 2008
@@ -59,19 +59,19 @@
       case DeadIncrement:
         BugType = "dead increment";
       case Standard:
-        if (!BugType) BugType = "dead store";
+        if (!BugType) BugType = "dead assignment";
         msg = "Value stored to '" + name + "' is never read";
         break;
         
       case Enclosing:
-        BugType = "dead store";
+        BugType = "dead nested assignment";
         msg = "Although the value stored to '" + name +
           "' is used in the enclosing expression, the value is never actually"
           " read from '" + name + "'";
         break;
     }
       
-    BR.EmitBasicReport(BugType, msg.c_str(), L, R);      
+    BR.EmitBasicReport(BugType, "Dead Store", msg.c_str(), L, R);      
   }
   
   void CheckVarDecl(VarDecl* VD, Expr* Ex, Expr* Val,

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

==============================================================================
--- cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/GRExprEngineInternalChecks.cpp Fri Sep 19 23:23:38 2008
@@ -293,7 +293,7 @@
   
 public:
   CheckAttrNonNull() :
-  BT("'nonnull' argument passed null",
+  BT("'nonnull' argument passed null", "API",
      "Null pointer passed as an argument to a 'nonnull' parameter") {}
 
   virtual bool Audit(ExplodedNode<GRState>* N, GRStateManager& VMgr) {

Modified: cfe/trunk/lib/Driver/HTMLDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/HTMLDiagnostics.cpp?rev=56385&r1=56384&r2=56385&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/HTMLDiagnostics.cpp (original)
+++ cfe/trunk/lib/Driver/HTMLDiagnostics.cpp Fri Sep 19 23:23:38 2008
@@ -259,6 +259,15 @@
     R.InsertStrBefore(SourceLocation::getFileLoc(FileID, 0), os.str());
   }
   
+  const std::string& BugCategory = D.getCategory();
+  
+  if (!BugCategory.empty()) {
+    std::string s;
+    llvm::raw_string_ostream os(s);
+    os << "\n<!-- BUGCATEGORY " << BugCategory << " -->\n";
+    R.InsertStrBefore(SourceLocation::getFileLoc(FileID, 0), os.str());
+  }
+  
   {
     std::string s;
     llvm::raw_string_ostream os(s);





More information about the cfe-commits mailing list