lebedev.ri created this revision. lebedev.ri added reviewers: dcoughlin, alexfh, aaron.ballman, george.karpenkov, NoQ. Herald added subscribers: a.sidorin, szepet, xazax.hun.
I would like to be able to trigger these debug checkers from clang-tidy, as a follow-up patch for https://reviews.llvm.org/D46159 Repository: rC Clang https://reviews.llvm.org/D46187 Files: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h lib/StaticAnalyzer/Core/AnalyzerOptions.cpp unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp Index: unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp =================================================================== --- unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp +++ unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp @@ -21,12 +21,18 @@ auto IsAlphaChecker = [](StringRef CheckerName) { return CheckerName.startswith("alpha"); }; - const auto &AllCheckers = - AnalyzerOptions::getRegisteredCheckers(/*IncludeExperimental=*/true); - EXPECT_FALSE(llvm::any_of(AllCheckers, IsDebugChecker)); + const auto &AllCheckers = AnalyzerOptions::getRegisteredCheckers( + /*IncludeExperimental=*/true, /*IncludeDebug=*/true); + EXPECT_TRUE(llvm::any_of(AllCheckers, IsDebugChecker)); EXPECT_TRUE(llvm::any_of(AllCheckers, IsAlphaChecker)); - const auto &StableCheckers = AnalyzerOptions::getRegisteredCheckers(); + const auto &AllNonDebugCheckers = AnalyzerOptions::getRegisteredCheckers( + /*IncludeExperimental=*/true, /*IncludeDebug=*/false); + EXPECT_FALSE(llvm::any_of(AllNonDebugCheckers, IsDebugChecker)); + EXPECT_TRUE(llvm::any_of(AllNonDebugCheckers, IsAlphaChecker)); + + const auto &StableCheckers = AnalyzerOptions::getRegisteredCheckers( + /*IncludeExperimental=false,IncludeDebug=false*/); EXPECT_FALSE(llvm::any_of(StableCheckers, IsDebugChecker)); EXPECT_FALSE(llvm::any_of(StableCheckers, IsAlphaChecker)); } Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp =================================================================== --- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp @@ -31,7 +31,8 @@ using namespace llvm; std::vector<StringRef> -AnalyzerOptions::getRegisteredCheckers(bool IncludeExperimental /* = false */) { +AnalyzerOptions::getRegisteredCheckers(bool IncludeExperimental /* = false */, + bool IncludeDebug /* = false */) { static const StringRef StaticAnalyzerChecks[] = { #define GET_CHECKERS #define CHECKER(FULLNAME, CLASS, DESCFILE, HELPTEXT, GROUPINDEX, HIDDEN) \ @@ -42,9 +43,10 @@ }; std::vector<StringRef> Result; for (StringRef CheckName : StaticAnalyzerChecks) { - if (!CheckName.startswith("debug.") && - (IncludeExperimental || !CheckName.startswith("alpha."))) - Result.push_back(CheckName); + if ((CheckName.startswith("alpha.") && !IncludeExperimental) || + (CheckName.startswith("debug.") && !IncludeDebug)) + continue; + Result.push_back(CheckName); } return Result; } Index: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h =================================================================== --- include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ include/clang/StaticAnalyzer/Core/AnalyzerOptions.h @@ -126,7 +126,8 @@ using ConfigTable = llvm::StringMap<std::string>; static std::vector<StringRef> - getRegisteredCheckers(bool IncludeExperimental = false); + getRegisteredCheckers(bool IncludeExperimental = false, + bool IncludeDebug = false); /// \brief Pair of checker name and enable/disable. std::vector<std::pair<std::string, bool>> CheckersControlList;
Index: unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp =================================================================== --- unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp +++ unittests/StaticAnalyzer/AnalyzerOptionsTest.cpp @@ -21,12 +21,18 @@ auto IsAlphaChecker = [](StringRef CheckerName) { return CheckerName.startswith("alpha"); }; - const auto &AllCheckers = - AnalyzerOptions::getRegisteredCheckers(/*IncludeExperimental=*/true); - EXPECT_FALSE(llvm::any_of(AllCheckers, IsDebugChecker)); + const auto &AllCheckers = AnalyzerOptions::getRegisteredCheckers( + /*IncludeExperimental=*/true, /*IncludeDebug=*/true); + EXPECT_TRUE(llvm::any_of(AllCheckers, IsDebugChecker)); EXPECT_TRUE(llvm::any_of(AllCheckers, IsAlphaChecker)); - const auto &StableCheckers = AnalyzerOptions::getRegisteredCheckers(); + const auto &AllNonDebugCheckers = AnalyzerOptions::getRegisteredCheckers( + /*IncludeExperimental=*/true, /*IncludeDebug=*/false); + EXPECT_FALSE(llvm::any_of(AllNonDebugCheckers, IsDebugChecker)); + EXPECT_TRUE(llvm::any_of(AllNonDebugCheckers, IsAlphaChecker)); + + const auto &StableCheckers = AnalyzerOptions::getRegisteredCheckers( + /*IncludeExperimental=false,IncludeDebug=false*/); EXPECT_FALSE(llvm::any_of(StableCheckers, IsDebugChecker)); EXPECT_FALSE(llvm::any_of(StableCheckers, IsAlphaChecker)); } Index: lib/StaticAnalyzer/Core/AnalyzerOptions.cpp =================================================================== --- lib/StaticAnalyzer/Core/AnalyzerOptions.cpp +++ lib/StaticAnalyzer/Core/AnalyzerOptions.cpp @@ -31,7 +31,8 @@ using namespace llvm; std::vector<StringRef> -AnalyzerOptions::getRegisteredCheckers(bool IncludeExperimental /* = false */) { +AnalyzerOptions::getRegisteredCheckers(bool IncludeExperimental /* = false */, + bool IncludeDebug /* = false */) { static const StringRef StaticAnalyzerChecks[] = { #define GET_CHECKERS #define CHECKER(FULLNAME, CLASS, DESCFILE, HELPTEXT, GROUPINDEX, HIDDEN) \ @@ -42,9 +43,10 @@ }; std::vector<StringRef> Result; for (StringRef CheckName : StaticAnalyzerChecks) { - if (!CheckName.startswith("debug.") && - (IncludeExperimental || !CheckName.startswith("alpha."))) - Result.push_back(CheckName); + if ((CheckName.startswith("alpha.") && !IncludeExperimental) || + (CheckName.startswith("debug.") && !IncludeDebug)) + continue; + Result.push_back(CheckName); } return Result; } Index: include/clang/StaticAnalyzer/Core/AnalyzerOptions.h =================================================================== --- include/clang/StaticAnalyzer/Core/AnalyzerOptions.h +++ include/clang/StaticAnalyzer/Core/AnalyzerOptions.h @@ -126,7 +126,8 @@ using ConfigTable = llvm::StringMap<std::string>; static std::vector<StringRef> - getRegisteredCheckers(bool IncludeExperimental = false); + getRegisteredCheckers(bool IncludeExperimental = false, + bool IncludeDebug = false); /// \brief Pair of checker name and enable/disable. std::vector<std::pair<std::string, bool>> CheckersControlList;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits