[clang-tools-extra] [clang-tidy][NFC] optimize unused using decls performance (PR #110200)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 26 19:44:59 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Congcong Cai (HerrCai0907)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/110200.diff
1 Files Affected:
- (modified) clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp (+9-7)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 90b317527ee410..3c8dd6e9d239d9 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -25,6 +25,13 @@ AST_MATCHER_P(DeducedTemplateSpecializationType, refsToTemplatedDecl,
return false;
}
+AST_MATCHER_P(Type, getTagDecl, clang::ast_matchers::internal::Matcher<TagDecl>,
+ DeclMatcher) {
+ if (const auto *ND = Node.getAsTagDecl())
+ return DeclMatcher.matches(*ND, Finder, Builder);
+ return false;
+}
+
} // namespace
// A function that helps to tell whether a TargetDecl in a UsingDecl will be
@@ -61,7 +68,8 @@ void UnusedUsingDeclsCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(userDefinedLiteral().bind("used"), this);
Finder->addMatcher(
loc(elaboratedType(unless(hasQualifier(nestedNameSpecifier())),
- hasUnqualifiedDesugaredType(type().bind("usedType")))),
+ hasUnqualifiedDesugaredType(
+ type(getTagDecl(tagDecl().bind("used")))))),
this);
// Cases where we can identify the UsingShadowDecl directly, rather than
// just its target.
@@ -139,12 +147,6 @@ void UnusedUsingDeclsCheck::check(const MatchFinder::MatchResult &Result) {
return;
}
- if (const auto *T = Result.Nodes.getNodeAs<Type>("usedType")) {
- if (const auto *ND = T->getAsTagDecl())
- RemoveNamedDecl(ND);
- return;
- }
-
if (const auto *UsedShadow =
Result.Nodes.getNodeAs<UsingShadowDecl>("usedShadow")) {
removeFromFoundDecls(UsedShadow->getTargetDecl());
``````````
</details>
https://github.com/llvm/llvm-project/pull/110200
More information about the cfe-commits
mailing list