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

Anna Zaks ganna at apple.com
Mon Aug 22 13:31:28 PDT 2011


Author: zaks
Date: Mon Aug 22 15:31:28 2011
New Revision: 138272

URL: http://llvm.org/viewvc/llvm-project?rev=138272&view=rev
Log:
Static Analyzer Diagnostics: Allow checkers to add ExtraDescriptiveText, now renamed into ExtraText, to the diagnostic without subclassing BugReport. 

Modified:
    cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.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=138272&r1=138271&r2=138272&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h Mon Aug 22 15:31:28 2011
@@ -62,6 +62,7 @@
 
   typedef const SourceRange *ranges_iterator;
   typedef llvm::ImmutableList<BugReporterVisitor*>::iterator visitor_iterator;
+  typedef SmallVector<StringRef, 2> ExtraTextList;
 
 protected:
   friend class BugReporter;
@@ -73,6 +74,7 @@
   FullSourceLoc Location;
   const ExplodedNode *ErrorNode;
   SmallVector<SourceRange, 4> Ranges;
+  ExtraTextList ExtraText;
 
   // Not the most efficient data structure, but we use an ImmutableList for the
   // Callbacks because it is safe to make additions to list during iteration.
@@ -115,8 +117,12 @@
   /// \brief This allows for addition of meta data to the diagnostic.
   ///
   /// Currently, only the HTMLDiagnosticClient knows how to display it. 
-  virtual std::pair<const char**,const char**> getExtraDescriptiveText() {
-    return std::make_pair((const char**)0,(const char**)0);
+  void addExtraText(StringRef S) {
+    ExtraText.push_back(S);
+  }
+
+  virtual const ExtraTextList &getExtraText() {
+    return ExtraText;
   }
 
   /// \brief Return the "definitive" location of the reported bug.

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp?rev=138272&r1=138271&r2=138272&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporter.cpp Mon Aug 22 15:31:28 2011
@@ -1860,10 +1860,12 @@
     return;
   
   // Get the meta data.
-  std::pair<const char**, const char**> Meta =
-    exampleReport->getExtraDescriptiveText();
-  for (const char** s = Meta.first; s != Meta.second; ++s)
-    D->addMeta(*s);
+  const BugReport::ExtraTextList &Meta =
+                                  exampleReport->getExtraText();
+  for (BugReport::ExtraTextList::const_iterator i = Meta.begin(),
+                                                e = Meta.end(); i != e; ++i) {
+    D->addMeta(*i);
+  }
 
   // Emit a summary diagnostic to the regular Diagnostics engine.
   BugReport::ranges_iterator Beg, End;

Modified: cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp?rev=138272&r1=138271&r2=138272&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/CFRefCount.cpp Mon Aug 22 15:31:28 2011
@@ -1797,9 +1797,9 @@
 //===----------------------------------------------------------------------===//
 // Error reporting.
 //===----------------------------------------------------------------------===//
+static void addExtraTextToCFReport(BugReport &R);
 
 namespace {
-
   //===-------------===//
   // Bug Descriptions. //
   //===-------------===//
@@ -1951,12 +1951,14 @@
       : BugReport(D, D.getDescription(), n) {
       if (registerVisitor)
         addVisitor(new CFRefReportVisitor(sym, tf));
+      addExtraTextToCFReport(*this);
     }
 
     CFRefReport(CFRefBug& D, const CFRefCount &tf,
                 ExplodedNode *n, SymbolRef sym, StringRef endText)
       : BugReport(D, D.getDescription(), endText, n) {
       addVisitor(new CFRefReportVisitor(sym, tf));
+      addExtraTextToCFReport(*this);
     }
 
     virtual ~CFRefReport() {}
@@ -1968,8 +1970,6 @@
       else
         return std::make_pair(ranges_iterator(), ranges_iterator());
     }
-
-    std::pair<const char**,const char**> getExtraDescriptiveText();
   };
 
   class CFRefLeakReport : public CFRefReport {
@@ -1985,8 +1985,6 @@
   };
 } // end anonymous namespace
 
-
-
 static const char* Msgs[] = {
   // GC only
   "Code is compiled to only use garbage collection",
@@ -2000,26 +1998,33 @@
   " (non-GC).  The bug occurs in non-GC mode"
 };
 
-std::pair<const char**,const char**> CFRefReport::getExtraDescriptiveText() {
-  CFRefCount& TF = static_cast<CFRefBug&>(getBugType()).getTF();
+// Add the metadata text.
+static void addExtraTextToCFReport(BugReport &R) {
+  CFRefCount& TF = static_cast<CFRefBug&>(R.getBugType()).getTF();
 
   switch (TF.getLangOptions().getGCMode()) {
-    default:
-      assert(false);
+  default:
+    assert(false);
 
-    case LangOptions::GCOnly:
-      assert (TF.isGCEnabled());
-      return std::make_pair(&Msgs[0], &Msgs[0]+1);
+  case LangOptions::GCOnly:
+    assert (TF.isGCEnabled());
+    R.addExtraText(Msgs[0]);
+    return;
 
-    case LangOptions::NonGC:
-      assert (!TF.isGCEnabled());
-      return std::make_pair(&Msgs[1], &Msgs[1]+1);
+  case LangOptions::NonGC:
+    assert (!TF.isGCEnabled());
+    R.addExtraText(Msgs[1]);
+    return;
 
-    case LangOptions::HybridGC:
-      if (TF.isGCEnabled())
-        return std::make_pair(&Msgs[2], &Msgs[2]+1);
-      else
-        return std::make_pair(&Msgs[3], &Msgs[3]+1);
+  case LangOptions::HybridGC:
+    if (TF.isGCEnabled()) {
+      R.addExtraText(Msgs[2]);
+      return;
+    }
+    else {
+      R.addExtraText(Msgs[3]);
+      return;
+    }
   }
 }
 





More information about the cfe-commits mailing list