@@ -53,6 +53,13 @@ LLVM_INSTANTIATE_REGISTRY(clang::tidy::ClangTidyModuleRegistry)
53
53
54
54
namespace clang::tidy {
55
55
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
+
56
63
namespace {
57
64
#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
58
65
#define ANALYZER_CHECK_NAME_PREFIX " clang-analyzer-"
@@ -342,6 +349,10 @@ ClangTidyASTConsumerFactory::ClangTidyASTConsumerFactory(
342
349
IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFS)
343
350
: Context(Context), OverlayFS(std::move(OverlayFS)),
344
351
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
345
356
for (ClangTidyModuleRegistry::entry E : ClangTidyModuleRegistry::entries ()) {
346
357
std::unique_ptr<ClangTidyModule> Module = E.instantiate ();
347
358
Module->addCheckFactories (*CheckFactories);
@@ -411,7 +422,10 @@ ClangTidyASTConsumerFactory::createASTConsumer(
411
422
.getCurrentWorkingDirectory ();
412
423
if (WorkingDir)
413
424
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
415
429
std::vector<std::unique_ptr<ClangTidyCheck>> Checks =
416
430
CheckFactories->createChecksForLanguage (&Context);
417
431
@@ -497,13 +511,13 @@ ClangTidyOptions::OptionMap ClangTidyASTConsumerFactory::getCheckOptions() {
497
511
return Options;
498
512
}
499
513
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 ) {
503
517
clang::tidy::ClangTidyContext Context (
504
518
std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions (),
505
519
Options),
506
- AllowEnablingAnalyzerAlphaCheckers);
520
+ AllowEnablingAnalyzerAlphaCheckers, false , ExperimentalCustomChecks );
507
521
ClangTidyASTConsumerFactory Factory (Context);
508
522
return Factory.getCheckNames ();
509
523
}
@@ -524,11 +538,12 @@ void filterCheckOptions(ClangTidyOptions &Options,
524
538
525
539
ClangTidyOptions::OptionMap
526
540
getCheckOptions (const ClangTidyOptions &Options,
527
- bool AllowEnablingAnalyzerAlphaCheckers) {
541
+ bool AllowEnablingAnalyzerAlphaCheckers,
542
+ bool ExperimentalCustomChecks) {
528
543
clang::tidy::ClangTidyContext Context (
529
544
std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions (),
530
545
Options),
531
- AllowEnablingAnalyzerAlphaCheckers);
546
+ AllowEnablingAnalyzerAlphaCheckers, false , ExperimentalCustomChecks );
532
547
ClangTidyDiagnosticConsumer DiagConsumer (Context);
533
548
auto DiagOpts = std::make_unique<DiagnosticOptions>();
534
549
DiagnosticsEngine DE (llvm::makeIntrusiveRefCnt<DiagnosticIDs>(), *DiagOpts,
@@ -665,15 +680,19 @@ void exportReplacements(const llvm::StringRef MainFilePath,
665
680
YAML << TUD;
666
681
}
667
682
668
- ChecksAndOptions
669
- getAllChecksAndOptions ( bool AllowEnablingAnalyzerAlphaCheckers ) {
683
+ ChecksAndOptions getAllChecksAndOptions ( bool AllowEnablingAnalyzerAlphaCheckers,
684
+ bool ExperimentalCustomChecks ) {
670
685
ChecksAndOptions Result;
671
686
ClangTidyOptions Opts;
672
687
Opts.Checks = " *" ;
673
688
clang::tidy::ClangTidyContext Context (
674
689
std::make_unique<DefaultOptionsProvider>(ClangTidyGlobalOptions (), Opts),
675
- AllowEnablingAnalyzerAlphaCheckers);
690
+ AllowEnablingAnalyzerAlphaCheckers, false , ExperimentalCustomChecks );
676
691
ClangTidyCheckFactories Factories;
692
+ #if CLANG_TIDY_ENABLE_QUERY_BASED_CUSTOM_CHECKS
693
+ if (ExperimentalCustomChecks && custom::RegisterCustomChecks)
694
+ custom::RegisterCustomChecks (Context.getOptions (), Factories);
695
+ #endif
677
696
for (const ClangTidyModuleRegistry::entry &Module :
678
697
ClangTidyModuleRegistry::entries ()) {
679
698
Module.instantiate ()->addCheckFactories (Factories);
0 commit comments