From 179e89f188aef6d973f25014ef5c3ab8d8e26d28 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Tue, 8 Nov 2016 07:43:42 +0000 Subject: [PATCH] Use AnalyzerOptions::getRegisteredCheckers() instead of clang/StaticAnalyzer/Checkers/Checkers.inc Summary: Depends on D26310. Reviewers: zaks.anna, hokein Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D26311 llvm-svn: 286219 --- clang-tools-extra/clang-tidy/ClangTidy.cpp | 70 +++++++++++++----------------- clang-tools-extra/clang-tidy/ClangTidy.h | 3 -- 2 files changed, 30 insertions(+), 43 deletions(-) diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index df86599..a03f3fe 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -56,15 +56,6 @@ namespace tidy { 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,36 @@ static void setStaticAnalyzerCheckerOpts(const ClangTidyOptions &Opts, } } +typedef std::vector> CheckersList; + +static CheckersList getCheckersControlList(GlobList &Filter) { + CheckersList List; + + const auto &RegisteredCheckers = + AnalyzerOptions::getRegisteredCheckers(/*IncludeExperimental=*/false); + 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 +400,6 @@ ClangTidyOptions::OptionMap ClangTidyASTConsumerFactory::getCheckOptions() { 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); diff --git a/clang-tools-extra/clang-tidy/ClangTidy.h b/clang-tools-extra/clang-tidy/ClangTidy.h index 4d53d0e..41df4d7 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.h +++ b/clang-tools-extra/clang-tidy/ClangTidy.h @@ -204,9 +204,6 @@ public: ClangTidyOptions::OptionMap getCheckOptions(); private: - typedef std::vector> CheckersList; - CheckersList getCheckersControlList(GlobList &Filter); - ClangTidyContext &Context; std::unique_ptr CheckFactories; }; -- 2.7.4