[clang] 41bbb87 - [NFC] Use hasAnyName matcher in place of anyOf(hasName()...)
Nathan James via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 7 06:31:22 PDT 2020
Author: Nathan James
Date: 2020-07-07T14:31:04+01:00
New Revision: 41bbb875e4da392ae37300d3a6282b6595f14503
URL: https://github.com/llvm/llvm-project/commit/41bbb875e4da392ae37300d3a6282b6595f14503
DIFF: https://github.com/llvm/llvm-project/commit/41bbb875e4da392ae37300d3a6282b6595f14503.diff
LOG: [NFC] Use hasAnyName matcher in place of anyOf(hasName()...)
Added:
Modified:
clang-tools-extra/clang-move/Move.cpp
clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
clang-tools-extra/clang-tidy/cert/CommandProcessorCheck.cpp
clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-move/Move.cpp b/clang-tools-extra/clang-move/Move.cpp
index 28184a0dce0c..3f09f68a8046 100644
--- a/clang-tools-extra/clang-move/Move.cpp
+++ b/clang-tools-extra/clang-move/Move.cpp
@@ -552,20 +552,22 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
// Match static functions/variable definitions which are defined in named
// namespaces.
- Optional<ast_matchers::internal::Matcher<NamedDecl>> HasAnySymbolNames;
+ SmallVector<std::string, 4> QualNames;
+ QualNames.reserve(Context->Spec.Names.size());
for (StringRef SymbolName : Context->Spec.Names) {
- llvm::StringRef GlobalSymbolName = SymbolName.trim().ltrim(':');
- const auto HasName = hasName(("::" + GlobalSymbolName).str());
- HasAnySymbolNames =
- HasAnySymbolNames ? anyOf(*HasAnySymbolNames, HasName) : HasName;
+ QualNames.push_back(("::" + SymbolName.trim().ltrim(':')).str());
}
- if (!HasAnySymbolNames) {
+ if (QualNames.empty()) {
llvm::errs() << "No symbols being moved.\n";
return;
}
+
+ ast_matchers::internal::Matcher<NamedDecl> HasAnySymbolNames =
+ hasAnyName(SmallVector<StringRef, 4>(QualNames.begin(), QualNames.end()));
+
auto InMovedClass =
- hasOutermostEnclosingClass(cxxRecordDecl(*HasAnySymbolNames));
+ hasOutermostEnclosingClass(cxxRecordDecl(HasAnySymbolNames));
// Matchers for helper declarations in old.cc.
auto InAnonymousNS = hasParent(namespaceDecl(isAnonymous()));
@@ -612,17 +614,17 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
// Create a MatchCallback for class declarations.
MatchCallbacks.push_back(std::make_unique<ClassDeclarationMatch>(this));
// Match moved class declarations.
- auto MovedClass = cxxRecordDecl(InOldFiles, *HasAnySymbolNames,
- isDefinition(), TopLevelDecl)
- .bind("moved_class");
+ auto MovedClass =
+ cxxRecordDecl(InOldFiles, HasAnySymbolNames, isDefinition(), TopLevelDecl)
+ .bind("moved_class");
Finder->addMatcher(MovedClass, MatchCallbacks.back().get());
// Match moved class methods (static methods included) which are defined
// outside moved class declaration.
- Finder->addMatcher(
- cxxMethodDecl(InOldFiles, ofOutermostEnclosingClass(*HasAnySymbolNames),
- isDefinition())
- .bind("class_method"),
- MatchCallbacks.back().get());
+ Finder->addMatcher(cxxMethodDecl(InOldFiles,
+ ofOutermostEnclosingClass(HasAnySymbolNames),
+ isDefinition())
+ .bind("class_method"),
+ MatchCallbacks.back().get());
// Match static member variable definition of the moved class.
Finder->addMatcher(
varDecl(InMovedClass, InOldFiles, isDefinition(), isStaticDataMember())
@@ -630,20 +632,20 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
MatchCallbacks.back().get());
MatchCallbacks.push_back(std::make_unique<FunctionDeclarationMatch>(this));
- Finder->addMatcher(functionDecl(InOldFiles, *HasAnySymbolNames, TopLevelDecl)
+ Finder->addMatcher(functionDecl(InOldFiles, HasAnySymbolNames, TopLevelDecl)
.bind("function"),
MatchCallbacks.back().get());
MatchCallbacks.push_back(std::make_unique<VarDeclarationMatch>(this));
Finder->addMatcher(
- varDecl(InOldFiles, *HasAnySymbolNames, TopLevelDecl).bind("var"),
+ varDecl(InOldFiles, HasAnySymbolNames, TopLevelDecl).bind("var"),
MatchCallbacks.back().get());
// Match enum definition in old.h. Enum helpers (which are defined in old.cc)
// will not be moved for now no matter whether they are used or not.
MatchCallbacks.push_back(std::make_unique<EnumDeclarationMatch>(this));
Finder->addMatcher(
- enumDecl(InOldHeader, *HasAnySymbolNames, isDefinition(), TopLevelDecl)
+ enumDecl(InOldHeader, HasAnySymbolNames, isDefinition(), TopLevelDecl)
.bind("enum"),
MatchCallbacks.back().get());
@@ -653,7 +655,7 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
MatchCallbacks.push_back(std::make_unique<TypeAliasMatch>(this));
Finder->addMatcher(namedDecl(anyOf(typedefDecl().bind("typedef"),
typeAliasDecl().bind("type_alias")),
- InOldHeader, *HasAnySymbolNames, TopLevelDecl),
+ InOldHeader, HasAnySymbolNames, TopLevelDecl),
MatchCallbacks.back().get());
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
index 4a15f5d111df..7c8c26370118 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MisplacedOperatorInStrlenInAllocCheck.cpp
@@ -19,12 +19,10 @@ namespace bugprone {
void MisplacedOperatorInStrlenInAllocCheck::registerMatchers(
MatchFinder *Finder) {
- const auto StrLenFunc = functionDecl(anyOf(
- hasName("::strlen"), hasName("::std::strlen"), hasName("::strnlen"),
- hasName("::std::strnlen"), hasName("::strnlen_s"),
- hasName("::std::strnlen_s"), hasName("::wcslen"),
- hasName("::std::wcslen"), hasName("::wcsnlen"), hasName("::std::wcsnlen"),
- hasName("::wcsnlen_s"), hasName("std::wcsnlen_s")));
+ const auto StrLenFunc = functionDecl(hasAnyName(
+ "::strlen", "::std::strlen", "::strnlen", "::std::strnlen", "::strnlen_s",
+ "::std::strnlen_s", "::wcslen", "::std::wcslen", "::wcsnlen",
+ "::std::wcsnlen", "::wcsnlen_s", "std::wcsnlen_s"));
const auto BadUse =
callExpr(callee(StrLenFunc),
@@ -42,12 +40,10 @@ void MisplacedOperatorInStrlenInAllocCheck::registerMatchers(
hasDescendant(BadUse)),
BadUse);
- const auto Alloc0Func =
- functionDecl(anyOf(hasName("::malloc"), hasName("std::malloc"),
- hasName("::alloca"), hasName("std::alloca")));
- const auto Alloc1Func =
- functionDecl(anyOf(hasName("::calloc"), hasName("std::calloc"),
- hasName("::realloc"), hasName("std::realloc")));
+ const auto Alloc0Func = functionDecl(
+ hasAnyName("::malloc", "std::malloc", "::alloca", "std::alloca"));
+ const auto Alloc1Func = functionDecl(
+ hasAnyName("::calloc", "std::calloc", "::realloc", "std::realloc"));
const auto Alloc0FuncPtr =
varDecl(hasType(isConstQualified()),
diff --git a/clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.cpp
index 04ae878b7024..2a6a0ae53a4f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MisplacedPointerArithmeticInAllocCheck.cpp
@@ -19,10 +19,9 @@ namespace bugprone {
void MisplacedPointerArithmeticInAllocCheck::registerMatchers(
MatchFinder *Finder) {
- const auto AllocFunc = functionDecl(
- anyOf(hasName("::malloc"), hasName("std::malloc"), hasName("::alloca"),
- hasName("::calloc"), hasName("std::calloc"), hasName("::realloc"),
- hasName("std::realloc")));
+ const auto AllocFunc =
+ functionDecl(hasAnyName("::malloc", "std::malloc", "::alloca", "::calloc",
+ "std::calloc", "::realloc", "std::realloc"));
const auto AllocFuncPtr =
varDecl(hasType(isConstQualified()),
diff --git a/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
index 844d672f121f..ee4681883964 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp
@@ -54,8 +54,7 @@ void SpuriouslyWakeUpFunctionsCheck::registerMatchers(MatchFinder *Finder) {
.bind("wait"));
auto hasWaitDescendantC = hasDescendant(
- callExpr(callee(functionDecl(
- anyOf(hasName("cnd_wait"), hasName("cnd_timedwait")))))
+ callExpr(callee(functionDecl(hasAnyName("cnd_wait", "cnd_timedwait"))))
.bind("wait"));
if (getLangOpts().CPlusPlus) {
// Check for `CON54-CPP`
diff --git a/clang-tools-extra/clang-tidy/cert/CommandProcessorCheck.cpp b/clang-tools-extra/clang-tidy/cert/CommandProcessorCheck.cpp
index 72b39d18f9f1..131ae9b3ed55 100644
--- a/clang-tools-extra/clang-tidy/cert/CommandProcessorCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cert/CommandProcessorCheck.cpp
@@ -19,8 +19,7 @@ namespace cert {
void CommandProcessorCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
callExpr(
- callee(functionDecl(anyOf(hasName("::system"), hasName("::popen"),
- hasName("::_popen")))
+ callee(functionDecl(hasAnyName("::system", "::popen", "::_popen"))
.bind("func")),
// Do not diagnose when the call expression passes a null pointer
// constant to system(); that only checks for the presence of a
diff --git a/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
index 2b3093338564..f4051c34aad9 100644
--- a/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cert/DontModifyStdNamespaceCheck.cpp
@@ -19,7 +19,7 @@ namespace cert {
void DontModifyStdNamespaceCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
namespaceDecl(unless(isExpansionInSystemHeader()),
- anyOf(hasName("std"), hasName("posix")),
+ hasAnyName("std", "posix"),
has(decl(unless(anyOf(
functionDecl(isExplicitTemplateSpecialization()),
cxxRecordDecl(isExplicitTemplateSpecialization()))))))
diff --git a/clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp b/clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
index dd7f76370887..13646ccbafa6 100644
--- a/clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/PreferIsaOrDynCastInConditionalsCheck.cpp
@@ -42,14 +42,13 @@ void PreferIsaOrDynCastInConditionalsCheck::registerMatchers(
auto CallExpression =
callExpr(
- allOf(unless(isMacroID()), unless(cxxMemberCallExpr()),
- allOf(callee(namedDecl(anyOf(hasName("isa"), hasName("cast"),
- hasName("cast_or_null"),
- hasName("dyn_cast"),
- hasName("dyn_cast_or_null")))
- .bind("func")),
- hasArgument(0, anyOf(declRefExpr().bind("arg"),
- cxxMemberCallExpr().bind("arg"))))))
+ allOf(
+ unless(isMacroID()), unless(cxxMemberCallExpr()),
+ allOf(callee(namedDecl(hasAnyName("isa", "cast", "cast_or_null",
+ "dyn_cast", "dyn_cast_or_null"))
+ .bind("func")),
+ hasArgument(0, anyOf(declRefExpr().bind("arg"),
+ cxxMemberCallExpr().bind("arg"))))))
.bind("rhs");
Finder->addMatcher(
diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
index 2156cd73d7c8..63f9f066f194 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
@@ -645,8 +645,7 @@ void AvoidBindCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
void AvoidBindCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
callExpr(
- callee(namedDecl(
- anyOf(hasName("::boost::bind"), hasName("::std::bind")))),
+ callee(namedDecl(hasAnyName("::boost::bind", "::std::bind"))),
hasArgument(
0, anyOf(expr(hasType(memberPointerType())).bind("ref"),
expr(hasParent(materializeTemporaryExpr().bind("ref"))),
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index dd18d866e508..215ba341f21f 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -146,9 +146,8 @@ StatementMatcher makeArrayLoopMatcher() {
/// - If the end iterator variable 'g' is defined, it is the same as 'f'.
StatementMatcher makeIteratorLoopMatcher() {
StatementMatcher BeginCallMatcher =
- cxxMemberCallExpr(
- argumentCountIs(0),
- callee(cxxMethodDecl(anyOf(hasName("begin"), hasName("cbegin")))))
+ cxxMemberCallExpr(argumentCountIs(0),
+ callee(cxxMethodDecl(hasAnyName("begin", "cbegin"))))
.bind(BeginCallName);
DeclarationMatcher InitDeclMatcher =
@@ -162,8 +161,7 @@ StatementMatcher makeIteratorLoopMatcher() {
varDecl(hasInitializer(anything())).bind(EndVarName);
StatementMatcher EndCallMatcher = cxxMemberCallExpr(
- argumentCountIs(0),
- callee(cxxMethodDecl(anyOf(hasName("end"), hasName("cend")))));
+ argumentCountIs(0), callee(cxxMethodDecl(hasAnyName("end", "cend"))));
StatementMatcher IteratorBoundMatcher =
expr(anyOf(ignoringParenImpCasts(
@@ -280,8 +278,7 @@ StatementMatcher makePseudoArrayLoopMatcher() {
));
StatementMatcher SizeCallMatcher = cxxMemberCallExpr(
- argumentCountIs(0),
- callee(cxxMethodDecl(anyOf(hasName("size"), hasName("length")))),
+ argumentCountIs(0), callee(cxxMethodDecl(hasAnyName("size", "length"))),
on(anyOf(hasType(pointsTo(RecordWithBeginEnd)),
hasType(RecordWithBeginEnd))));
diff --git a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
index e0be718decb2..4182b51c02b0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
@@ -541,14 +541,11 @@ static bool hasUnguardedAccess(const FieldDecl *FD, ProgramStateRef State) {
auto FieldAccessM = memberExpr(hasDeclaration(equalsNode(FD))).bind("access");
auto AssertLikeM = callExpr(callee(functionDecl(
- anyOf(hasName("exit"), hasName("panic"), hasName("error"),
- hasName("Assert"), hasName("assert"), hasName("ziperr"),
- hasName("assfail"), hasName("db_error"), hasName("__assert"),
- hasName("__assert2"), hasName("_wassert"), hasName("__assert_rtn"),
- hasName("__assert_fail"), hasName("dtrace_assfail"),
- hasName("yy_fatal_error"), hasName("_XCAssertionFailureHandler"),
- hasName("_DTAssertionFailureHandler"),
- hasName("_TSAssertionFailureHandler")))));
+ hasAnyName("exit", "panic", "error", "Assert", "assert", "ziperr",
+ "assfail", "db_error", "__assert", "__assert2", "_wassert",
+ "__assert_rtn", "__assert_fail", "dtrace_assfail",
+ "yy_fatal_error", "_XCAssertionFailureHandler",
+ "_DTAssertionFailureHandler", "_TSAssertionFailureHandler"))));
auto NoReturnFuncM = callExpr(callee(functionDecl(isNoReturn())));
More information about the cfe-commits
mailing list