<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif">FYI,<br></div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">This commit breaks clang tests. It appears that StaticAnalysisTests misses dependency on clangFrontend.</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif">--Artem</div><div class="gmail_default" style="font-family:verdana,sans-serif"><br></div><div class="gmail_default"><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">[60/134] Linking CXX executable tools/clang/unittests/StaticAnalyzer/StaticAnalysisTests</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">FAILED: tools/clang/unittests/StaticAnalyzer/StaticAnalysisTests </span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">: && /usr/local/google/home/tra/local/clang/bin/clang++   -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -fno-common -Woverloaded-virtual -Wno-nested-anon-types -g  -fuse-ld=lld -Xlinker --gdb-index -fuse-ld=lld -Wl,--color-diagnostics -Wl,-allow-shlib-undefined tools/clang/unittests/StaticAnalyzer/CMakeFiles/StaticAnalysisTests.dir/AnalyzerOptionsTest.cpp.o tools/clang/unittests/StaticAnalyzer/CMakeFiles/StaticAnalysisTests.dir/RegisterCustomCheckersTest.cpp.o  -o tools/clang/unittests/StaticAnalyzer/StaticAnalysisTests  lib/libLLVMSupport.so.7svn -lpthread lib/libgtest_main.so.7svn lib/libgtest.so.7svn -lpthread lib/libclangBasic.so.7svn lib/libclangAnalysis.so.7svn lib/libclangStaticAnalyzerCore.so.7svn lib/libclangStaticAnalyzerFrontend.so.7svn lib/libclangTooling.so.7svn -Wl,-rpath,/usr/local/google/home/tra/work/llvm/build/release+assert/lib && :</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">/usr/local/google/home/tra/local/clang/bin/ld.lld: error: undefined symbol: clang::FrontendAction::FrontendAction()</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">>>> referenced by FrontendAction.h:235 (/usr/local/google/home/tra/work/llvm/repo/clang/include/clang/Frontend/FrontendAction.h:235)</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">>>>               tools/clang/unittests/StaticAnalyzer/CMakeFiles/StaticAnalysisTests.dir/RegisterCustomCheckersTest.cpp.o:(clang::ASTFrontendAction::ASTFrontendAction())</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px"><br></span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">/usr/local/google/home/tra/local/clang/bin/ld.lld: error: undefined symbol: vtable for clang::ASTFrontendAction</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">>>> referenced by FrontendAction.h:235 (/usr/local/google/home/tra/work/llvm/repo/clang/include/clang/Frontend/FrontendAction.h:235)</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">>>>               tools/clang/unittests/StaticAnalyzer/CMakeFiles/StaticAnalysisTests.dir/RegisterCustomCheckersTest.cpp.o:(clang::ASTFrontendAction::ASTFrontendAction())</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px"><br></span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">/usr/local/google/home/tra/local/clang/bin/ld.lld: error: undefined symbol: clang::FrontendAction::~FrontendAction()</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">>>> referenced by FrontendAction.h:225 (/usr/local/google/home/tra/work/llvm/repo/clang/include/clang/Frontend/FrontendAction.h:225)</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">>>>               tools/clang/unittests/StaticAnalyzer/CMakeFiles/StaticAnalysisTests.dir/RegisterCustomCheckersTest.cpp.o:(clang::ASTFrontendAction::~ASTFrontendAction())</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px"><br></span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">/usr/local/google/home/tra/local/clang/bin/ld.lld: error: undefined symbol: clang::PCHContainerOperations::PCHContainerOperations()</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">>>> referenced by new_allocator.h:136 (/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/ext/new_allocator.h:136)</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">>>>               tools/clang/unittests/StaticAnalyzer/CMakeFiles/StaticAnalysisTests.dir/RegisterCustomCheckersTest.cpp.o:(void __gnu_cxx::new_allocator<clang::PCHContainerOperations>::construct<clang::PCHContainerOperations>(clang::PCHContainerOperations*))</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px"><br></span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">/usr/local/google/home/tra/local/clang/bin/ld.lld: error: undefined symbol: clang::ASTFrontendAction::ExecuteAction()</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">>>> referenced by RegisterCustomCheckersTest.cpp</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">>>>               tools/clang/unittests/StaticAnalyzer/CMakeFiles/StaticAnalysisTests.dir/RegisterCustomCheckersTest.cpp.o:(vtable for clang::ento::(anonymous namespace)::TestAction)</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px"><br></span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">/usr/local/google/home/tra/local/clang/bin/ld.lld: error: undefined symbol: clang::FrontendAction::shouldEraseOutputFiles()</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">>>> referenced by RegisterCustomCheckersTest.cpp</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">>>>               tools/clang/unittests/StaticAnalyzer/CMakeFiles/StaticAnalysisTests.dir/RegisterCustomCheckersTest.cpp.o:(vtable for clang::ento::(anonymous namespace)::TestAction)</span></font></div><div class="gmail_default"><font face="verdana, sans-serif"><span style="font-size:13px">clang: error: linker command failed with exit code 1 (use -v to see invocation)</span></font></div><div style="font-family:verdana,sans-serif"><br></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Jun 27, 2018 at 8:00 AM Alexander Kornienko via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: alexfh<br>
Date: Wed Jun 27 07:56:12 2018<br>
New Revision: 335740<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=335740&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=335740&view=rev</a><br>
Log:<br>
[analyzer] Allow registering custom statically-linked analyzer checkers<br>
<br>
Summary:<br>
Add an extension point to allow registration of statically-linked Clang Static<br>
Analyzer checkers that are not a part of the Clang tree. This extension point<br>
employs the mechanism used when checkers are registered from dynamically loaded<br>
plugins.<br>
<br>
Reviewers: george.karpenkov, NoQ, xazax.hun, dcoughlin<br>
<br>
Reviewed By: george.karpenkov<br>
<br>
Subscribers: mgorny, mikhail.ramalho, rnkovacs, xazax.hun, szepet, a.sidorin, cfe-commits<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D45718" rel="noreferrer" target="_blank">https://reviews.llvm.org/D45718</a><br>
<br>
Added:<br>
    cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp<br>
Modified:<br>
    cfe/trunk/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h<br>
    cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h<br>
    cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp<br>
    cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp<br>
    cfe/trunk/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp<br>
    cfe/trunk/unittests/StaticAnalyzer/CMakeLists.txt<br>
<br>
Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h?rev=335740&r1=335739&r2=335740&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h?rev=335740&r1=335739&r2=335740&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h (original)<br>
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/AnalysisConsumer.h Wed Jun 27 07:56:12 2018<br>
@@ -17,6 +17,7 @@<br>
<br>
 #include "clang/AST/ASTConsumer.h"<br>
 #include "clang/Basic/LLVM.h"<br>
+#include <functional><br>
 #include <memory><br>
<br>
 namespace clang {<br>
@@ -29,10 +30,24 @@ class CompilerInstance;<br>
 namespace ento {<br>
 class PathDiagnosticConsumer;<br>
 class CheckerManager;<br>
+class CheckerRegistry;<br>
<br>
 class AnalysisASTConsumer : public ASTConsumer {<br>
 public:<br>
   virtual void AddDiagnosticConsumer(PathDiagnosticConsumer *Consumer) = 0;<br>
+<br>
+  /// This method allows registering statically linked custom checkers that are<br>
+  /// not a part of the Clang tree. It employs the same mechanism that is used<br>
+  /// by plugins.<br>
+  ///<br>
+  /// Example:<br>
+  ///<br>
+  ///   Consumer->AddCheckerRegistrationFn([] (CheckerRegistry& Registry) {<br>
+  ///     Registry.addChecker<MyCustomChecker>("example.MyCustomChecker",<br>
+  ///                                          "Description");<br>
+  ///   });<br>
+  virtual void<br>
+  AddCheckerRegistrationFn(std::function<void(CheckerRegistry &)> Fn) = 0;<br>
 };<br>
<br>
 /// CreateAnalysisConsumer - Creates an ASTConsumer to run various code<br>
<br>
Modified: cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h?rev=335740&r1=335739&r2=335740&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h?rev=335740&r1=335739&r2=335740&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h (original)<br>
+++ cfe/trunk/include/clang/StaticAnalyzer/Frontend/CheckerRegistration.h Wed Jun 27 07:56:12 2018<br>
@@ -11,6 +11,7 @@<br>
 #define LLVM_CLANG_STATICANALYZER_FRONTEND_CHECKERREGISTRATION_H<br>
<br>
 #include "clang/Basic/LLVM.h"<br>
+#include <functional><br>
 #include <memory><br>
 #include <string><br>
<br>
@@ -21,10 +22,13 @@ namespace clang {<br>
<br>
 namespace ento {<br>
   class CheckerManager;<br>
+  class CheckerRegistry;<br>
<br>
-  std::unique_ptr<CheckerManager><br>
-  createCheckerManager(AnalyzerOptions &opts, const LangOptions &langOpts,<br>
-                       ArrayRef<std::string> plugins, DiagnosticsEngine &diags);<br>
+  std::unique_ptr<CheckerManager> createCheckerManager(<br>
+      AnalyzerOptions &opts, const LangOptions &langOpts,<br>
+      ArrayRef<std::string> plugins,<br>
+      ArrayRef<std::function<void(CheckerRegistry &)>> checkerRegistrationFns,<br>
+      DiagnosticsEngine &diags);<br>
<br>
 } // end ento namespace<br>
<br>
<br>
Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp?rev=335740&r1=335739&r2=335740&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp?rev=335740&r1=335739&r2=335740&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp Wed Jun 27 07:56:12 2018<br>
@@ -164,6 +164,8 @@ class AnalysisConsumer : public Analysis<br>
   /// Bug Reporter to use while recursively visiting Decls.<br>
   BugReporter *RecVisitorBR;<br>
<br>
+  std::vector<std::function<void(CheckerRegistry &)>> CheckerRegistrationFns;<br>
+<br>
 public:<br>
   ASTContext *Ctx;<br>
   const Preprocessor &PP;<br>
@@ -293,8 +295,9 @@ public:<br>
<br>
   void Initialize(ASTContext &Context) override {<br>
     Ctx = &Context;<br>
-    checkerMgr = createCheckerManager(*Opts, PP.getLangOpts(), Plugins,<br>
-                                      PP.getDiagnostics());<br>
+    checkerMgr =<br>
+        createCheckerManager(*Opts, PP.getLangOpts(), Plugins,<br>
+                             CheckerRegistrationFns, PP.getDiagnostics());<br>
<br>
     Mgr = llvm::make_unique<AnalysisManager>(<br>
         *Ctx, PP.getDiagnostics(), PP.getLangOpts(), PathConsumers,<br>
@@ -385,6 +388,10 @@ public:<br>
     PathConsumers.push_back(Consumer);<br>
   }<br>
<br>
+  void AddCheckerRegistrationFn(std::function<void(CheckerRegistry&)> Fn) override {<br>
+    CheckerRegistrationFns.push_back(std::move(Fn));<br>
+  }<br>
+<br>
 private:<br>
   void storeTopLevelDecls(DeclGroupRef DG);<br>
   std::string getFunctionName(const Decl *D);<br>
<br>
Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp?rev=335740&r1=335739&r2=335740&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp?rev=335740&r1=335739&r2=335740&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/CheckerRegistration.cpp Wed Jun 27 07:56:12 2018<br>
@@ -111,16 +111,21 @@ getCheckerOptList(const AnalyzerOptions<br>
   return checkerOpts;<br>
 }<br>
<br>
-std::unique_ptr<CheckerManager><br>
-ento::createCheckerManager(AnalyzerOptions &opts, const LangOptions &langOpts,<br>
-                           ArrayRef<std::string> plugins,<br>
-                           DiagnosticsEngine &diags) {<br>
+std::unique_ptr<CheckerManager> ento::createCheckerManager(<br>
+    AnalyzerOptions &opts, const LangOptions &langOpts,<br>
+    ArrayRef<std::string> plugins,<br>
+    ArrayRef<std::function<void(CheckerRegistry &)>> checkerRegistrationFns,<br>
+    DiagnosticsEngine &diags) {<br>
   std::unique_ptr<CheckerManager> checkerMgr(<br>
       new CheckerManager(langOpts, opts));<br>
<br>
   SmallVector<CheckerOptInfo, 8> checkerOpts = getCheckerOptList(opts);<br>
<br>
   ClangCheckerRegistry allCheckers(plugins, &diags);<br>
+<br>
+  for (const auto &Fn : checkerRegistrationFns)<br>
+    Fn(allCheckers);<br>
+<br>
   allCheckers.initializeManager(*checkerMgr, checkerOpts);<br>
   allCheckers.validateCheckerOptions(opts, diags);<br>
   checkerMgr->finishedCheckerRegistration();<br>
<br>
Modified: cfe/trunk/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp?rev=335740&r1=335739&r2=335740&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp?rev=335740&r1=335739&r2=335740&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp (original)<br>
+++ cfe/trunk/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp Wed Jun 27 07:56:12 2018<br>
@@ -1,4 +1,4 @@<br>
-//===- unittest/Analysis/AnalyzerOptionsTest.cpp - SA Options test --------===//<br>
+//===- unittest/StaticAnalyzer/AnalyzerOptionsTest.cpp - SA Options test --===//<br>
 //<br>
 //                     The LLVM Compiler Infrastructure<br>
 //<br>
<br>
Modified: cfe/trunk/unittests/StaticAnalyzer/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/CMakeLists.txt?rev=335740&r1=335739&r2=335740&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/CMakeLists.txt?rev=335740&r1=335739&r2=335740&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/unittests/StaticAnalyzer/CMakeLists.txt (original)<br>
+++ cfe/trunk/unittests/StaticAnalyzer/CMakeLists.txt Wed Jun 27 07:56:12 2018<br>
@@ -4,11 +4,14 @@ set(LLVM_LINK_COMPONENTS<br>
<br>
 add_clang_unittest(StaticAnalysisTests<br>
   AnalyzerOptionsTest.cpp<br>
+  RegisterCustomCheckersTest.cpp<br>
   )<br>
<br>
 target_link_libraries(StaticAnalysisTests<br>
   PRIVATE<br>
   clangBasic<br>
   clangAnalysis<br>
-  clangStaticAnalyzerCore <br>
+  clangStaticAnalyzerCore<br>
+  clangStaticAnalyzerFrontend<br>
+  clangTooling<br>
   )<br>
<br>
Added: cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp?rev=335740&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp?rev=335740&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp (added)<br>
+++ cfe/trunk/unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp Wed Jun 27 07:56:12 2018<br>
@@ -0,0 +1,80 @@<br>
+//===- unittests/StaticAnalyzer/RegisterCustomCheckersTest.cpp ------------===//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "clang/Frontend/CompilerInstance.h"<br>
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"<br>
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"<br>
+#include "clang/StaticAnalyzer/Core/Checker.h"<br>
+#include "clang/StaticAnalyzer/Core/CheckerRegistry.h"<br>
+#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"<br>
+#include "clang/StaticAnalyzer/Frontend/AnalysisConsumer.h"<br>
+#include "clang/Tooling/Tooling.h"<br>
+#include "gtest/gtest.h"<br>
+<br>
+namespace clang {<br>
+namespace ento {<br>
+namespace {<br>
+<br>
+class CustomChecker : public Checker<check::ASTCodeBody> {<br>
+public:<br>
+  void checkASTCodeBody(const Decl *D, AnalysisManager &Mgr,<br>
+                        BugReporter &BR) const {<br>
+    BR.EmitBasicReport(D, this, "Custom diagnostic", categories::LogicError,<br>
+                       "Custom diagnostic description",<br>
+                       PathDiagnosticLocation(D, Mgr.getSourceManager()), {});<br>
+  }<br>
+};<br>
+<br>
+class TestAction : public ASTFrontendAction {<br>
+  class DiagConsumer : public PathDiagnosticConsumer {<br>
+    llvm::raw_ostream &Output;<br>
+<br>
+  public:<br>
+    DiagConsumer(llvm::raw_ostream &Output) : Output(Output) {}<br>
+    void FlushDiagnosticsImpl(std::vector<const PathDiagnostic *> &Diags,<br>
+                              FilesMade *filesMade) override {<br>
+      for (const auto *PD : Diags)<br>
+        Output << PD->getCheckName() << ":" << PD->getShortDescription();<br>
+    }<br>
+<br>
+    StringRef getName() const override { return "Test"; }<br>
+  };<br>
+<br>
+  llvm::raw_ostream &DiagsOutput;<br>
+<br>
+public:<br>
+  TestAction(llvm::raw_ostream &DiagsOutput) : DiagsOutput(DiagsOutput) {}<br>
+<br>
+  std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &Compiler,<br>
+                                                 StringRef File) override {<br>
+    std::unique_ptr<AnalysisASTConsumer> AnalysisConsumer =<br>
+        CreateAnalysisConsumer(Compiler);<br>
+    AnalysisConsumer->AddDiagnosticConsumer(new DiagConsumer(DiagsOutput));<br>
+    Compiler.getAnalyzerOpts()->CheckersControlList = {<br>
+        {"custom.CustomChecker", true}};<br>
+    AnalysisConsumer->AddCheckerRegistrationFn([](CheckerRegistry &Registry) {<br>
+      Registry.addChecker<CustomChecker>("custom.CustomChecker", "Description");<br>
+    });<br>
+    return AnalysisConsumer;<br>
+  }<br>
+};<br>
+<br>
+<br>
+TEST(RegisterCustomCheckers, RegisterChecker) {<br>
+  std::string Diags;<br>
+  {<br>
+    llvm::raw_string_ostream OS(Diags);<br>
+    EXPECT_TRUE(tooling::runToolOnCode(new TestAction(OS), "void f() {;}"));<br>
+  }<br>
+  EXPECT_EQ(Diags, "custom.CustomChecker:Custom diagnostic description");<br>
+}<br>
+<br>
+}<br>
+}<br>
+}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">--Artem Belevich</div></div>