2010-12-03 08:58:14 +08:00
|
|
|
//===--- TextPathDiagnostics.cpp - Text Diagnostics for Paths ---*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the TextPathDiagnostics object.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2011-09-27 09:43:33 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/PathDiagnosticConsumers.h"
|
2010-12-03 08:58:14 +08:00
|
|
|
#include "clang/Lex/Preprocessor.h"
|
2012-12-04 17:13:33 +08:00
|
|
|
#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
|
2010-12-03 08:58:14 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
using namespace clang;
|
2010-12-23 15:20:52 +08:00
|
|
|
using namespace ento;
|
2010-12-03 08:58:14 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2010-12-03 09:17:19 +08:00
|
|
|
/// \brief Simple path diagnostic client used for outputting as diagnostic notes
|
2010-12-03 08:58:14 +08:00
|
|
|
/// the sequence of events.
|
2011-09-26 08:51:36 +08:00
|
|
|
class TextPathDiagnostics : public PathDiagnosticConsumer {
|
2010-12-03 08:58:14 +08:00
|
|
|
const std::string OutputFile;
|
2011-09-26 07:23:43 +08:00
|
|
|
DiagnosticsEngine &Diag;
|
2010-12-03 08:58:14 +08:00
|
|
|
|
|
|
|
public:
|
2011-09-26 07:23:43 +08:00
|
|
|
TextPathDiagnostics(const std::string& output, DiagnosticsEngine &diag)
|
2010-12-03 08:58:14 +08:00
|
|
|
: OutputFile(output), Diag(diag) {}
|
|
|
|
|
2012-01-26 07:47:14 +08:00
|
|
|
void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,
|
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
2012-08-17 01:45:23 +08:00
|
|
|
FilesMade *filesMade);
|
2010-12-03 08:58:14 +08:00
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
virtual StringRef getName() const {
|
2010-12-03 08:58:14 +08:00
|
|
|
return "TextPathDiagnostics";
|
|
|
|
}
|
|
|
|
|
2010-12-03 10:03:26 +08:00
|
|
|
PathGenerationScheme getGenerationScheme() const { return Minimal; }
|
2010-12-03 08:58:14 +08:00
|
|
|
bool supportsLogicalOpControlFlow() const { return true; }
|
|
|
|
bool supportsAllBlockEdges() const { return true; }
|
2012-08-04 07:08:54 +08:00
|
|
|
virtual bool supportsCrossFileDiagnostics() const { return true; }
|
2010-12-03 08:58:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
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
2012-08-17 01:45:23 +08:00
|
|
|
void ento::createTextPathDiagnosticConsumer(PathDiagnosticConsumers &C,
|
|
|
|
const std::string& out,
|
|
|
|
const Preprocessor &PP) {
|
|
|
|
C.push_back(new TextPathDiagnostics(out, PP.getDiagnostics()));
|
2010-12-03 08:58:14 +08:00
|
|
|
}
|
|
|
|
|
2012-01-26 07:47:14 +08:00
|
|
|
void TextPathDiagnostics::FlushDiagnosticsImpl(
|
|
|
|
std::vector<const PathDiagnostic *> &Diags,
|
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
2012-08-17 01:45:23 +08:00
|
|
|
FilesMade *) {
|
2012-01-26 07:47:14 +08:00
|
|
|
for (std::vector<const PathDiagnostic *>::iterator it = Diags.begin(),
|
|
|
|
et = Diags.end(); it != et; ++it) {
|
|
|
|
const PathDiagnostic *D = *it;
|
2012-08-04 07:08:54 +08:00
|
|
|
|
|
|
|
PathPieces FlatPath = D->path.flatten(/*ShouldFlattenMacros=*/true);
|
|
|
|
for (PathPieces::const_iterator I = FlatPath.begin(), E = FlatPath.end();
|
2012-02-08 12:32:34 +08:00
|
|
|
I != E; ++I) {
|
2012-01-26 07:47:14 +08:00
|
|
|
unsigned diagID =
|
|
|
|
Diag.getDiagnosticIDs()->getCustomDiagID(DiagnosticIDs::Note,
|
2012-02-08 12:32:34 +08:00
|
|
|
(*I)->getString());
|
|
|
|
Diag.Report((*I)->getLocation().asLocation(), diagID);
|
2012-01-26 07:47:14 +08:00
|
|
|
}
|
2010-12-03 08:58:14 +08:00
|
|
|
}
|
|
|
|
}
|