From 8df2a62ae65530c8a489e7520ff02c2ab6f5db94 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 llvm-svn: 286218 --- .../clang/StaticAnalyzer/Core/AnalyzerOptions.h | 3 +++ clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp | 19 +++++++++++++++++++ .../unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp | 17 +++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h b/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h index 68d26c7..4fb50de 100644 --- a/clang/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ b/clang/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/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp index 86c194e..1542263 100644 --- a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ b/clang/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/clang/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp b/clang/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp index 33f1740..891c88d 100644 --- a/clang/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp +++ b/clang/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.7.4