r286218 - Add a method to get the list of registered static analyzer checkers.
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 7 23:23:32 PST 2016
Author: alexfh
Date: Tue Nov 8 01:23:32 2016
New Revision: 286218
URL: http://llvm.org/viewvc/llvm-project?rev=286218&view=rev
Log:
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
Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
cfe/trunk/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp
Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h?rev=286218&r1=286217&r2=286218&view=diff
==============================================================================
--- cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/AnalyzerOptions.h Tue Nov 8 01:23:32 2016
@@ -125,6 +125,9 @@ class AnalyzerOptions : public RefCounte
public:
typedef llvm::StringMap<std::string> ConfigTable;
+ static std::vector<StringRef>
+ getRegisteredCheckers(bool IncludeExperimental = false);
+
/// \brief Pair of checker name and enable/disable.
std::vector<std::pair<std::string, bool> > CheckersControlList;
Modified: cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp?rev=286218&r1=286217&r2=286218&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp Tue Nov 8 01:23:32 2016
@@ -23,6 +23,25 @@ using namespace clang;
using namespace ento;
using namespace llvm;
+std::vector<StringRef>
+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<StringRef> 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 =
Modified: cfe/trunk/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp?rev=286218&r1=286217&r2=286218&view=diff
==============================================================================
--- cfe/trunk/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp (original)
+++ cfe/trunk/unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp Tue Nov 8 01:23:32 2016
@@ -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";
More information about the cfe-commits
mailing list