Allow multiple PathDiagnosticConsumers to be used with a BugReporter at the same time.

This fixes several issues:

- removes egregious hack where PlistDiagnosticConsumer would forward to HTMLDiagnosticConsumer,
but diagnostics wouldn't be generated consistently in the same way if PlistDiagnosticConsumer
was used by itself.

- emitting diagnostics to the terminal (using clang's diagnostic machinery) is no longer a special
case, just another PathDiagnosticConsumer.  This also magically resolved some duplicate warnings,
as we now use PathDiagnosticConsumer's diagnostic pruning, which has scope for the entire translation
unit, not just the scope of a BugReporter (which is limited to a particular ExprEngine).

As an interesting side-effect, diagnostics emitted to the terminal also have their trailing "." stripped,
just like with diagnostics emitted to plists and HTML.  This required some tests to be updated, but now
the tests have higher fidelity with what users will see.

There are some inefficiencies in this patch.  We currently generate the report graph (from the ExplodedGraph)
once per PathDiagnosticConsumer, which is a bit wasteful, but that could be pulled up higher in the
logic stack.  There is some intended duplication, however, as we now generate different PathDiagnostics (for the same issue)
for different PathDiagnosticConsumers.  This is necessary to produce the diagnostics that a particular
consumer expects.

llvm-svn: 162028
This commit is contained in:
Ted Kremenek
2012-08-16 17:45:23 +00:00
parent d624bfb5f0
commit 9bf9af92a4
24 changed files with 321 additions and 293 deletions

View File

@@ -45,7 +45,7 @@ public:
virtual ~HTMLDiagnostics() { FlushDiagnostics(NULL); }
virtual void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
SmallVectorImpl<std::string> *FilesMade);
FilesMade *filesMade);
virtual StringRef getName() const {
return "HTMLDiagnostics";
@@ -63,7 +63,7 @@ public:
const char *HighlightEnd = "</span>");
void ReportDiag(const PathDiagnostic& D,
SmallVectorImpl<std::string> *FilesMade);
FilesMade *filesMade);
};
} // end anonymous namespace
@@ -76,10 +76,10 @@ HTMLDiagnostics::HTMLDiagnostics(const std::string& prefix,
FilePrefix.appendComponent("report");
}
PathDiagnosticConsumer*
ento::createHTMLDiagnosticConsumer(const std::string& prefix,
const Preprocessor &PP) {
return new HTMLDiagnostics(prefix, PP);
void ento::createHTMLDiagnosticConsumer(PathDiagnosticConsumers &C,
const std::string& prefix,
const Preprocessor &PP) {
C.push_back(new HTMLDiagnostics(prefix, PP));
}
//===----------------------------------------------------------------------===//
@@ -88,15 +88,15 @@ ento::createHTMLDiagnosticConsumer(const std::string& prefix,
void HTMLDiagnostics::FlushDiagnosticsImpl(
std::vector<const PathDiagnostic *> &Diags,
SmallVectorImpl<std::string> *FilesMade) {
FilesMade *filesMade) {
for (std::vector<const PathDiagnostic *>::iterator it = Diags.begin(),
et = Diags.end(); it != et; ++it) {
ReportDiag(**it, FilesMade);
ReportDiag(**it, filesMade);
}
}
void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D,
SmallVectorImpl<std::string> *FilesMade) {
FilesMade *filesMade) {
// Create the HTML directory if it is missing.
if (!createdDir) {
@@ -266,8 +266,10 @@ void HTMLDiagnostics::ReportDiag(const PathDiagnostic& D,
return;
}
if (FilesMade)
FilesMade->push_back(llvm::sys::path::filename(H.str()));
if (filesMade) {
filesMade->push_back(std::make_pair(StringRef(getName()),
llvm::sys::path::filename(H.str())));
}
// Emit the HTML to disk.
for (RewriteBuffer::iterator I = Buf->begin(), E = Buf->end(); I!=E; ++I)