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

Alexander Kornienko alexfh at google.com
Wed Jan 22 23:39:16 PST 2014


Ted, Jordan, could you review this patch as well?

Thanks!
On 21 Jan 2014 20:08, "Alexander Kornienko" <alexfh at google.com> wrote:

> Jordan, could you take a look at this patch?
> On 15 Jan 2014 18:09, "Alexander Kornienko" <alexfh at google.com> wrote:
>
>> Hi jordan_rose, krememek,
>>
>> 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).
>>
>> http://llvm-reviews.chandlerc.com/D2556
>>
>> Files:
>>   include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h
>>   lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
>>
>> Index: include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h
>> ===================================================================
>> --- include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h
>> +++ include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h
>> @@ -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 ReplaceDiagnosticConsumer(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
>>
>> Index: lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
>> ===================================================================
>> --- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
>> +++ lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
>> @@ -145,7 +145,7 @@
>>
>>  namespace {
>>
>> -class AnalysisConsumer : public ASTConsumer,
>> +class AnalysisConsumer : public AnalysisASTConsumer,
>>                           public
>> DataRecursiveASTVisitor<AnalysisConsumer> {
>>    enum {
>>      AM_None = 0,
>> @@ -377,6 +377,16 @@
>>      return true;
>>    }
>>
>> +  virtual void
>> +  ReplaceDiagnosticConsumer(PathDiagnosticConsumer *Consumer)
>> LLVM_OVERRIDE {
>> +    for (PathDiagnosticConsumers::iterator I = PathConsumers.begin(),
>> +                                           E = PathConsumers.end();
>> +         I != E; ++I)
>> +      delete *I;
>> +    PathConsumers.clear();
>> +    PathConsumers.push_back(Consumer);
>> +  }
>> +
>>  private:
>>    void storeTopLevelDecls(DeclGroupRef DG);
>>
>> @@ -687,10 +697,10 @@
>>  // 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);
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140123/23f78855/attachment.html>


More information about the cfe-commits mailing list