Allow specifying a custom PathDiagnosticConsumer for use with the static analyzer.

Summary:
Make objects returned by CreateAnalysisConsumer expose an interface,
that allows providing a custom PathDiagnosticConsumer, so that users can have
raw data in a form easily usable from the code (unlike plist/HTML in a file).

Reviewers: jordan_rose, krememek

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D2556

llvm-svn: 200710
This commit is contained in:
Alexander Kornienko 2014-02-03 18:37:50 +00:00
parent d5e2f094d4
commit 7a712cea71
3 changed files with 37 additions and 22 deletions

View File

@ -54,6 +54,7 @@ NumConstraints
enum AnalysisDiagClients {
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATFN) PD_##NAME,
#include "clang/StaticAnalyzer/Core/Analyses.def"
PD_NONE,
NUM_ANALYSIS_DIAG_CLIENTS
};

View File

@ -15,26 +15,32 @@
#ifndef LLVM_CLANG_GR_ANALYSISCONSUMER_H
#define LLVM_CLANG_GR_ANALYSISCONSUMER_H
#include "clang/AST/ASTConsumer.h"
#include "clang/Basic/LLVM.h"
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
#include <string>
namespace clang {
class ASTConsumer;
class Preprocessor;
class DiagnosticsEngine;
namespace ento {
class CheckerManager;
class AnalysisASTConsumer : public ASTConsumer {
public:
virtual void AddDiagnosticConsumer(PathDiagnosticConsumer *Consumer) = 0;
};
/// CreateAnalysisConsumer - Creates an ASTConsumer to run various code
/// analysis passes. (The set of analyses run is controlled by command-line
/// options.)
ASTConsumer* CreateAnalysisConsumer(const Preprocessor &pp,
const std::string &output,
AnalyzerOptionsRef opts,
ArrayRef<std::string> plugins);
AnalysisASTConsumer *CreateAnalysisConsumer(const Preprocessor &pp,
const std::string &output,
AnalyzerOptionsRef opts,
ArrayRef<std::string> plugins);
} // end GR namespace

View File

@ -145,7 +145,7 @@ public:
namespace {
class AnalysisConsumer : public ASTConsumer,
class AnalysisConsumer : public AnalysisASTConsumer,
public DataRecursiveASTVisitor<AnalysisConsumer> {
enum {
AM_None = 0,
@ -208,21 +208,24 @@ public:
}
void DigestAnalyzerOptions() {
// Create the PathDiagnosticConsumer.
ClangDiagPathDiagConsumer *clangDiags =
new ClangDiagPathDiagConsumer(PP.getDiagnostics());
PathConsumers.push_back(clangDiags);
if (Opts->AnalysisDiagOpt != PD_NONE) {
// Create the PathDiagnosticConsumer.
ClangDiagPathDiagConsumer *clangDiags =
new ClangDiagPathDiagConsumer(PP.getDiagnostics());
PathConsumers.push_back(clangDiags);
if (Opts->AnalysisDiagOpt == PD_TEXT) {
clangDiags->enablePaths();
if (Opts->AnalysisDiagOpt == PD_TEXT) {
clangDiags->enablePaths();
} else if (!OutDir.empty()) {
switch (Opts->AnalysisDiagOpt) {
default:
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN) \
case PD_##NAME: CREATEFN(*Opts.getPtr(), PathConsumers, OutDir, PP);\
break;
} else if (!OutDir.empty()) {
switch (Opts->AnalysisDiagOpt) {
default:
#define ANALYSIS_DIAGNOSTICS(NAME, CMDFLAG, DESC, CREATEFN) \
case PD_##NAME: \
CREATEFN(*Opts.getPtr(), PathConsumers, OutDir, PP); \
break;
#include "clang/StaticAnalyzer/Core/Analyses.def"
}
}
}
@ -377,6 +380,11 @@ public:
return true;
}
virtual void
AddDiagnosticConsumer(PathDiagnosticConsumer *Consumer) LLVM_OVERRIDE {
PathConsumers.push_back(Consumer);
}
private:
void storeTopLevelDecls(DeclGroupRef DG);
@ -687,10 +695,10 @@ void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
// AnalysisConsumer creation.
//===----------------------------------------------------------------------===//
ASTConsumer* ento::CreateAnalysisConsumer(const Preprocessor& pp,
const std::string& outDir,
AnalyzerOptionsRef opts,
ArrayRef<std::string> plugins) {
AnalysisASTConsumer *
ento::CreateAnalysisConsumer(const Preprocessor &pp, const std::string &outDir,
AnalyzerOptionsRef opts,
ArrayRef<std::string> plugins) {
// Disable the effects of '-Werror' when using the AnalysisConsumer.
pp.getDiagnostics().setWarningsAsErrors(false);