@@ -53,6 +53,13 @@ LLVM_INSTANTIATE_REGISTRY(clang::tidy::ClangTidyModuleRegistry)
5353
5454namespace clang::tidy {
5555
56+ #if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
57+ namespace custom {
58+ void (*RegisterCustomChecks)(const ClangTidyOptions &O,
59+ ClangTidyCheckFactories &Factories) = nullptr ;
60+ } // namespace custom
61+ #endif
62+
5663namespace {
5764#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
5865#define ANALYZER_CHECK_NAME_PREFIX " clang-analyzer-"
@@ -342,6 +349,10 @@ ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
342349 IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS)
343350 : Context(Context), OverlayFS(std::move(OverlayFS)),
344351 CheckFactories(new ClangTidyCheckFactories) {
352+ #if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
353+ if (Context.canExperimentalCustomChecks () && custom::RegisterCustomChecks)
354+ custom::RegisterCustomChecks (Context.getOptions (), *CheckFactories);
355+ #endif
345356 for (ClangTidyModuleRegistry::entry E : ClangTidyModuleRegistry::entries ()) {
346357 std::unique_ptr<ClangTidyModule> Module = E.instantiate ();
347358 Module->addCheckFactories (*CheckFactories);
@@ -411,7 +422,10 @@ ClangTidyASTConsumerFactory::createASTConsumer(
411422 .getCurrentWorkingDirectory ();
412423 if (WorkingDir)
413424 Context.setCurrentBuildDirectory (WorkingDir.get ());
414-
425+ #if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
426+ if (Context.canExperimentalCustomChecks () && custom::RegisterCustomChecks)
427+ custom::RegisterCustomChecks (Context.getOptions (), *CheckFactories);
428+ #endif
415429 std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
416430 CheckFactories->createChecksForLanguage (&Context);
417431
@@ -497,13 +511,13 @@ ClangTidyOptions::OptionMap ClangTidyASTConsumerFactory::getCheckOptions() {
497511 return Options;
498512}
499513
500- std::vector<std::string>
501- getCheckNames ( const ClangTidyOptions &Options ,
502- bool AllowEnablingAnalyzerAlphaCheckers ) {
514+ std::vector<std::string> getCheckNames ( const ClangTidyOptions &Options,
515+ bool AllowEnablingAnalyzerAlphaCheckers ,
516+ bool ExperimentalCustomChecks ) {
503517 clang::tidy::ClangTidyContext Context (
504518 std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions (),
505519 Options),
506- AllowEnablingAnalyzerAlphaCheckers);
520+ AllowEnablingAnalyzerAlphaCheckers, false , ExperimentalCustomChecks );
507521 ClangTidyASTConsumerFactory Factory (Context);
508522 return Factory.getCheckNames ();
509523}
@@ -524,11 +538,12 @@ void filterCheckOptions(ClangTidyOptions &Options,
524538
525539ClangTidyOptions::OptionMap
526540getCheckOptions (const ClangTidyOptions &Options,
527- bool AllowEnablingAnalyzerAlphaCheckers) {
541+ bool AllowEnablingAnalyzerAlphaCheckers,
542+ bool ExperimentalCustomChecks) {
528543 clang::tidy::ClangTidyContext Context (
529544 std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions (),
530545 Options),
531- AllowEnablingAnalyzerAlphaCheckers);
546+ AllowEnablingAnalyzerAlphaCheckers, false , ExperimentalCustomChecks );
532547 ClangTidyDiagnosticConsumer DiagConsumer (Context);
533548 auto DiagOpts = std::make_unique<DiagnosticOptions>();
534549 DiagnosticsEngine DE (llvm::makeIntrusiveRefCnt<DiagnosticIDs>(), *DiagOpts,
@@ -665,15 +680,19 @@ void exportReplacements(const llvm::StringRef MainFilePath,
665680 YAML << TUD;
666681}
667682
668- ChecksAndOptions
669- getAllChecksAndOptions ( bool AllowEnablingAnalyzerAlphaCheckers ) {
683+ ChecksAndOptions getAllChecksAndOptions ( bool AllowEnablingAnalyzerAlphaCheckers,
684+ bool ExperimentalCustomChecks ) {
670685 ChecksAndOptions Result;
671686 ClangTidyOptions Opts;
672687 Opts.Checks = " *" ;
673688 clang::tidy::ClangTidyContext Context (
674689 std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions (), Opts),
675- AllowEnablingAnalyzerAlphaCheckers);
690+ AllowEnablingAnalyzerAlphaCheckers, false , ExperimentalCustomChecks );
676691 ClangTidyCheckFactories Factories;
692+ #if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
693+ if (ExperimentalCustomChecks && custom::RegisterCustomChecks)
694+ custom::RegisterCustomChecks (Context.getOptions (), Factories);
695+ #endif
677696 for (const ClangTidyModuleRegistry::entry &Module :
678697 ClangTidyModuleRegistry::entries ()) {
679698 Module.instantiate ()->addCheckFactories (Factories);
0 commit comments