From bfd8fbd05a2033ec35b3a24b0d59725c68fec5b9 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Tue, 8 Nov 2016 07:23:32 +0000 Subject: [PATCH] Add a method to get the list of registered static analyzer checkers. Summary: This provides a better interface for clang-tidy and encapsulates the knowledge about experimental checkers instead of leaving this to the clients. Reviewers: zaks.anna Subscribers: a.sidorin, NoQ, dcoughlin, cfe-commits Differential Revision: https://reviews.llvm.org/D26310 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286218 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../StaticAnalyzer/Core/AnalyzerOptions.h | 3 +++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp | 19 +++++++++++++++++++ .../StaticAnalyzer/AnalyzerOptionsTest.cpp | 17 +++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h index 68d26c791d..4fb50deb0f 100644 --- a/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ b/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h @@ -125,6 +125,9 @@ class AnalyzerOptions : public RefCountedBase { public: typedef llvm::StringMap ConfigTable; + static std::vector + getRegisteredCheckers(bool IncludeExperimental = false); + /// \brief Pair of checker name and enable/disable. std::vector > CheckersControlList; diff --git a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp index 86c194e8fa..15422633ba 100644 --- a/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ b/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp @@ -23,6 +23,25 @@ using namespace clang; using namespace ento; using namespace llvm; +std::vector +AnalyzerOptions::getRegisteredCheckers(bool IncludeExperimental /* = false */) { + 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 + }; + std::vector Result; + for (StringRef CheckName : StaticAnalyzerChecks) { + if (!CheckName.startswith("debug.") && + (IncludeExperimental || !CheckName.startswith("alpha."))) + Result.push_back(CheckName); + } + return Result; +} + AnalyzerOptions::UserModeKind AnalyzerOptions::getUserMode() { if (UserMode == UMK_NotSet) { StringRef ModeStr = diff --git a/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp b/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp index 33f1740bea..891c88da30 100644 --- a/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp +++ b/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp @@ -14,6 +14,23 @@ namespace clang { namespace ento { +TEST(StaticAnalyzerOptions, getRegisteredCheckers) { + auto IsDebugChecker = [](StringRef CheckerName) { + return CheckerName.startswith("debug"); + }; + auto IsAlphaChecker = [](StringRef CheckerName) { + return CheckerName.startswith("alpha"); + }; + const auto &AllCheckers = + AnalyzerOptions::getRegisteredCheckers(/*IncludeExperimental=*/true); + EXPECT_FALSE(llvm::any_of(AllCheckers, IsDebugChecker)); + EXPECT_TRUE(llvm::any_of(AllCheckers, IsAlphaChecker)); + + const auto &StableCheckers = AnalyzerOptions::getRegisteredCheckers(); + EXPECT_FALSE(llvm::any_of(StableCheckers, IsDebugChecker)); + EXPECT_FALSE(llvm::any_of(StableCheckers, IsAlphaChecker)); +} + TEST(StaticAnalyzerOptions, SearchInParentPackageTests) { AnalyzerOptions Opts; Opts.Config["Outer.Inner.CheckerOne:Option"] = "true"; -- 2.40.0