From 7f2531cb41448852ec78de90fc1d3c0149c95d7d Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Mon, 22 Aug 2011 20:31:28 +0000 Subject: [PATCH] Static Analyzer Diagnostics: Allow checkers to add ExtraDescriptiveText, now renamed into ExtraText, to the diagnostic without subclassing BugReport. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138272 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Core/BugReporter/BugReporter.h | 10 ++++- lib/StaticAnalyzer/Core/BugReporter.cpp | 10 +++-- lib/StaticAnalyzer/Core/CFRefCount.cpp | 45 ++++++++++--------- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h b/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h index cfe7048a77..95b27e7861 100644 --- a/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h +++ b/include/clang/StaticAnalyzer/Core/BugReporter/BugReporter.h @@ -62,6 +62,7 @@ public: typedef const SourceRange *ranges_iterator; typedef llvm::ImmutableList::iterator visitor_iterator; + typedef SmallVector ExtraTextList; protected: friend class BugReporter; @@ -73,6 +74,7 @@ protected: FullSourceLoc Location; const ExplodedNode *ErrorNode; SmallVector 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 @@ public: /// \brief This allows for addition of meta data to the diagnostic. /// /// Currently, only the HTMLDiagnosticClient knows how to display it. - virtual std::pair 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. diff --git a/lib/StaticAnalyzer/Core/BugReporter.cpp b/lib/StaticAnalyzer/Core/BugReporter.cpp index 31786dd002..fc28c587d2 100644 --- a/lib/StaticAnalyzer/Core/BugReporter.cpp +++ b/lib/StaticAnalyzer/Core/BugReporter.cpp @@ -1860,10 +1860,12 @@ void BugReporter::FlushReport(BugReportEquivClass& EQ) { return; // Get the meta data. - std::pair 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; diff --git a/lib/StaticAnalyzer/Core/CFRefCount.cpp b/lib/StaticAnalyzer/Core/CFRefCount.cpp index 4ade451ba5..e1cf34c2db 100644 --- a/lib/StaticAnalyzer/Core/CFRefCount.cpp +++ b/lib/StaticAnalyzer/Core/CFRefCount.cpp @@ -1797,9 +1797,9 @@ void CFRefCount::BindingsPrinter::Print(raw_ostream &Out, //===----------------------------------------------------------------------===// // Error reporting. //===----------------------------------------------------------------------===// +static void addExtraTextToCFReport(BugReport &R); namespace { - //===-------------===// // Bug Descriptions. // //===-------------===// @@ -1951,12 +1951,14 @@ namespace { : 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 @@ namespace { else return std::make_pair(ranges_iterator(), ranges_iterator()); } - - std::pair getExtraDescriptiveText(); }; class CFRefLeakReport : public CFRefReport { @@ -1985,8 +1985,6 @@ namespace { }; } // end anonymous namespace - - static const char* Msgs[] = { // GC only "Code is compiled to only use garbage collection", @@ -2000,26 +1998,33 @@ static const char* Msgs[] = { " (non-GC). The bug occurs in non-GC mode" }; -std::pair CFRefReport::getExtraDescriptiveText() { - CFRefCount& TF = static_cast(getBugType()).getTF(); +// Add the metadata text. +static void addExtraTextToCFReport(BugReport &R) { + CFRefCount& TF = static_cast(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; + } } } -- 2.40.0