[PATCH] Clang-tidy: don't create ASTConsumers not needed for the set of checks we perform.

Alexander Kornienko alexfh at google.com
Thu Feb 13 06:36:46 PST 2014


  Added ClangTidyCheckFactories::empty(), use it instead of begin() != end()

Hi djasper, klimek,

http://llvm-reviews.chandlerc.com/D2763

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D2763?vs=7054&id=7057#toc

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/ClangTidyModule.h

Index: clang-tidy/ClangTidy.cpp
===================================================================
--- clang-tidy/ClangTidy.cpp
+++ clang-tidy/ClangTidy.cpp
@@ -152,18 +152,24 @@
        I != E; ++I)
     (*I)->registerPPCallbacks(Compiler);
 
+  SmallVector<ASTConsumer *, 2> Consumers;
+  if (CheckFactories->empty())
+    Consumers.push_back(Finder.newASTConsumer());
+
   AnalyzerOptionsRef Options = Compiler.getAnalyzerOpts();
   Options->CheckersControlList = getCheckersControlList();
-  Options->AnalysisStoreOpt = RegionStoreModel;
-  Options->AnalysisDiagOpt = PD_NONE;
-  Options->AnalyzeNestedBlocks = true;
-  Options->eagerlyAssumeBinOpBifurcation = true;
-  ento::AnalysisASTConsumer *AnalysisConsumer = ento::CreateAnalysisConsumer(
-      Compiler.getPreprocessor(), Compiler.getFrontendOpts().OutputFile,
-      Options, Compiler.getFrontendOpts().Plugins);
-  AnalysisConsumer->AddDiagnosticConsumer(
-      new AnalyzerDiagnosticConsumer(Context));
-  ASTConsumer *Consumers[] = { Finder.newASTConsumer(), AnalysisConsumer };
+  if (!Options->CheckersControlList.empty()) {
+    Options->AnalysisStoreOpt = RegionStoreModel;
+    Options->AnalysisDiagOpt = PD_NONE;
+    Options->AnalyzeNestedBlocks = true;
+    Options->eagerlyAssumeBinOpBifurcation = true;
+    ento::AnalysisASTConsumer *AnalysisConsumer = ento::CreateAnalysisConsumer(
+        Compiler.getPreprocessor(), Compiler.getFrontendOpts().OutputFile,
+        Options, Compiler.getFrontendOpts().Plugins);
+    AnalysisConsumer->AddDiagnosticConsumer(
+        new AnalyzerDiagnosticConsumer(Context));
+    Consumers.push_back(AnalysisConsumer);
+  }
   return new MultiplexConsumer(Consumers);
 }
 
Index: clang-tidy/ClangTidyModule.h
===================================================================
--- clang-tidy/ClangTidyModule.h
+++ clang-tidy/ClangTidyModule.h
@@ -90,6 +90,7 @@
   typedef std::map<std::string, CheckFactoryBase *> FactoryMap;
   FactoryMap::const_iterator begin() const { return Factories.begin(); }
   FactoryMap::const_iterator end() const { return Factories.end(); }
+  bool empty() const { return Factories.empty(); }
 
 private:
   FactoryMap Factories;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2763.3.patch
Type: text/x-patch
Size: 2175 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140213/f3479465/attachment.bin>


More information about the cfe-commits mailing list