@@ -53,6 +53,11 @@ LLVM_INSTANTIATE_REGISTRY(clang::tidy::ClangTidyModuleRegistry)
5353
5454namespace clang::tidy {
5555
56+ namespace custom {
57+ extern void registerCustomChecks (const ClangTidyOptions &O,
58+ ClangTidyCheckFactories &Factories);
59+ } // namespace custom
60+
5661namespace {
5762#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
5863#define ANALYZER_CHECK_NAME_PREFIX " clang-analyzer-"
@@ -342,6 +347,10 @@ ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
342347 IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS)
343348 : Context(Context), OverlayFS(std::move(OverlayFS)),
344349 CheckFactories(new ClangTidyCheckFactories) {
350+ #if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
351+ if (Context.canExperimentalCustomChecks ())
352+ custom::registerCustomChecks (Context.getOptions (), *CheckFactories);
353+ #endif
345354 for (ClangTidyModuleRegistry::entry E : ClangTidyModuleRegistry::entries ()) {
346355 std::unique_ptr<ClangTidyModule> Module = E.instantiate ();
347356 Module->addCheckFactories (*CheckFactories);
@@ -411,7 +420,10 @@ ClangTidyASTConsumerFactory::createASTConsumer(
411420 .getCurrentWorkingDirectory ();
412421 if (WorkingDir)
413422 Context.setCurrentBuildDirectory (WorkingDir.get ());
414-
423+ #if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
424+ if (Context.canExperimentalCustomChecks ())
425+ custom::registerCustomChecks (Context.getOptions (), *CheckFactories);
426+ #endif
415427 std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
416428 CheckFactories->createChecksForLanguage (&Context);
417429
@@ -497,13 +509,13 @@ ClangTidyOptions::OptionMap ClangTidyASTConsumerFactory::getCheckOptions() {
497509 return Options;
498510}
499511
500- std::vector<std::string>
501- getCheckNames ( const ClangTidyOptions &Options ,
502- bool AllowEnablingAnalyzerAlphaCheckers ) {
512+ std::vector<std::string> getCheckNames ( const ClangTidyOptions &Options,
513+ bool AllowEnablingAnalyzerAlphaCheckers ,
514+ bool ExperimentalCustomChecks ) {
503515 clang::tidy::ClangTidyContext Context (
504516 std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions (),
505517 Options),
506- AllowEnablingAnalyzerAlphaCheckers);
518+ AllowEnablingAnalyzerAlphaCheckers, false , ExperimentalCustomChecks );
507519 ClangTidyASTConsumerFactory Factory (Context);
508520 return Factory.getCheckNames ();
509521}
@@ -524,11 +536,12 @@ void filterCheckOptions(ClangTidyOptions &Options,
524536
525537ClangTidyOptions::OptionMap
526538getCheckOptions (const ClangTidyOptions &Options,
527- bool AllowEnablingAnalyzerAlphaCheckers) {
539+ bool AllowEnablingAnalyzerAlphaCheckers,
540+ bool ExperimentalCustomChecks) {
528541 clang::tidy::ClangTidyContext Context (
529542 std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions (),
530543 Options),
531- AllowEnablingAnalyzerAlphaCheckers);
544+ AllowEnablingAnalyzerAlphaCheckers, false , ExperimentalCustomChecks );
532545 ClangTidyDiagnosticConsumer DiagConsumer (Context);
533546 auto DiagOpts = std::make_unique<DiagnosticOptions>();
534547 DiagnosticsEngine DE (llvm::makeIntrusiveRefCnt<DiagnosticIDs>(), *DiagOpts,
@@ -665,15 +678,19 @@ void exportReplacements(const llvm::StringRef MainFilePath,
665678 YAML << TUD;
666679}
667680
668- ChecksAndOptions
669- getAllChecksAndOptions ( bool AllowEnablingAnalyzerAlphaCheckers ) {
681+ ChecksAndOptions getAllChecksAndOptions ( bool AllowEnablingAnalyzerAlphaCheckers,
682+ bool ExperimentalCustomChecks ) {
670683 ChecksAndOptions Result;
671684 ClangTidyOptions Opts;
672685 Opts.Checks = " *" ;
673686 clang::tidy::ClangTidyContext Context (
674687 std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions (), Opts),
675- AllowEnablingAnalyzerAlphaCheckers);
688+ AllowEnablingAnalyzerAlphaCheckers, false , ExperimentalCustomChecks );
676689 ClangTidyCheckFactories Factories;
690+ #if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
691+ if (ExperimentalCustomChecks)
692+ custom::registerCustomChecks (Context.getOptions (), Factories);
693+ #endif
677694 for (const ClangTidyModuleRegistry::entry &Module :
678695 ClangTidyModuleRegistry::entries ()) {
679696 Module.instantiate ()->addCheckFactories (Factories);
0 commit comments