Index: clang-tidy/ClangTidy.h =================================================================== --- clang-tidy/ClangTidy.h +++ clang-tidy/ClangTidy.h @@ -204,9 +204,6 @@ ClangTidyOptions::OptionMap getCheckOptions(); private: - typedef std::vector> CheckersList; - CheckersList getCheckersControlList(GlobList &Filter); - ClangTidyContext &Context; std::unique_ptr CheckFactories; }; Index: clang-tidy/ClangTidy.cpp =================================================================== --- clang-tidy/ClangTidy.cpp +++ clang-tidy/ClangTidy.cpp @@ -56,15 +56,6 @@ namespace { static const char *AnalyzerCheckNamePrefix = "clang-analyzer-"; -static const StringRef StaticAnalyzerChecks[] = { -#define GET_CHECKERS -#define CHECKER(FULLNAME, CLASS, DESCFILE, HELPTEXT, GROUPINDEX, HIDDEN) \ - FULLNAME, -#include "clang/StaticAnalyzer/Checkers/Checkers.inc" -#undef CHECKER -#undef GET_CHECKERS -}; - class AnalyzerDiagnosticConsumer : public ento::PathDiagnosticConsumer { public: AnalyzerDiagnosticConsumer(ClangTidyContext &Context) : Context(Context) {} @@ -296,6 +287,37 @@ } } +typedef std::vector> CheckersList; + +static CheckersList getCheckersControlList(GlobList &Filter) { + CheckersList List; + + const bool IncludeExperimentalCheckers = false; + const auto &RegisteredCheckers = + AnalyzerOptions::getRegisteredCheckers(IncludeExperimentalCheckers); + bool AnalyzerChecksEnabled = false; + for (StringRef CheckName : RegisteredCheckers) { + std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str()); + AnalyzerChecksEnabled |= Filter.contains(ClangTidyCheckName); + } + + if (!AnalyzerChecksEnabled) + return List; + + // List all static analyzer checkers that our filter enables. + // + // Always add all core checkers if any other static analyzer check is enabled. + // This is currently necessary, as other path sensitive checks rely on the + // core checkers. + for (StringRef CheckName : RegisteredCheckers) { + std::string ClangTidyCheckName((AnalyzerCheckNamePrefix + CheckName).str()); + + if (CheckName.startswith("core") || Filter.contains(ClangTidyCheckName)) + List.emplace_back(CheckName, true); + } + return List; +} + std::unique_ptr ClangTidyASTConsumerFactory::CreateASTConsumer( clang::CompilerInstance &Compiler, StringRef File) { @@ -379,37 +401,6 @@ return Options; } -ClangTidyASTConsumerFactory::CheckersList -ClangTidyASTConsumerFactory::getCheckersControlList(GlobList &Filter) { - CheckersList List; - - bool AnalyzerChecksEnabled = false; - for (StringRef CheckName : StaticAnalyzerChecks) { - std::string Checker((AnalyzerCheckNamePrefix + CheckName).str()); - AnalyzerChecksEnabled = - AnalyzerChecksEnabled || - (!CheckName.startswith("debug") && Filter.contains(Checker)); - } - - if (AnalyzerChecksEnabled) { - // Run our regex against all possible static analyzer checkers. Note that - // debug checkers print values / run programs to visualize the CFG and are - // thus not applicable to clang-tidy in general. - // - // Always add all core checkers if any other static analyzer checks are - // enabled. This is currently necessary, as other path sensitive checks - // rely on the core checkers. - for (StringRef CheckName : StaticAnalyzerChecks) { - std::string Checker((AnalyzerCheckNamePrefix + CheckName).str()); - - if (CheckName.startswith("core") || - (!CheckName.startswith("debug") && Filter.contains(Checker))) - List.push_back(std::make_pair(CheckName, true)); - } - } - return List; -} - DiagnosticBuilder ClangTidyCheck::diag(SourceLocation Loc, StringRef Message, DiagnosticIDs::Level Level) { return Context->diag(CheckName, Loc, Message, Level);