[clang] [clang][NFC] Refactor replaceExternalDecls to use llvm::any_of (PR #143275)
Samarth Narang via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 8 19:31:54 PDT 2025
https://github.com/snarang181 updated https://github.com/llvm/llvm-project/pull/143275
>From c18c91f7f8f4332696dd309a5164c568f32c137b Mon Sep 17 00:00:00 2001
From: Samarth Narang <snarang at umass.edu>
Date: Sat, 7 Jun 2025 12:21:17 -0400
Subject: [PATCH 1/2] Replace loop with llvm:any_of
---
clang/include/clang/AST/DeclContextInternals.h | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/clang/include/clang/AST/DeclContextInternals.h b/clang/include/clang/AST/DeclContextInternals.h
index b17b7627ac90c..a1071f62d5fae 100644
--- a/clang/include/clang/AST/DeclContextInternals.h
+++ b/clang/include/clang/AST/DeclContextInternals.h
@@ -176,14 +176,10 @@ class StoredDeclsList {
DeclListNode::Decls *Tail = erase_if([Decls](NamedDecl *ND) {
if (ND->isFromASTFile())
return true;
- // FIXME: Can we get rid of this loop completely?
- for (NamedDecl *D : Decls)
- // Only replace the local declaration if the external declaration has
- // higher visibilities.
- if (D->getModuleOwnershipKind() <= ND->getModuleOwnershipKind() &&
- D->declarationReplaces(ND, /*IsKnownNewer=*/false))
- return true;
- return false;
+ return llvm::any_of(Decls, [ND](NamedDecl *D) {
+ return D->getModuleOwnershipKind() <= ND->getModuleOwnershipKind() &&
+ D->declarationReplaces(ND, /*IsKnownNewer=*/false);
+ });
});
// Don't have any pending external decls any more.
>From 84b94745cddff8acf0539ab28f0b3e258b1c3dcb Mon Sep 17 00:00:00 2001
From: Samarth Narang <snarang at umass.edu>
Date: Sun, 8 Jun 2025 22:07:43 -0400
Subject: [PATCH 2/2] Retain comments
---
clang/include/clang/AST/DeclContextInternals.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/clang/include/clang/AST/DeclContextInternals.h b/clang/include/clang/AST/DeclContextInternals.h
index a1071f62d5fae..9bde6a459a2c9 100644
--- a/clang/include/clang/AST/DeclContextInternals.h
+++ b/clang/include/clang/AST/DeclContextInternals.h
@@ -177,6 +177,8 @@ class StoredDeclsList {
if (ND->isFromASTFile())
return true;
return llvm::any_of(Decls, [ND](NamedDecl *D) {
+ // Only replace the local declaration if the external declaration has
+ // a higher module ownership kind, or if the local declaration is
return D->getModuleOwnershipKind() <= ND->getModuleOwnershipKind() &&
D->declarationReplaces(ND, /*IsKnownNewer=*/false);
});
More information about the cfe-commits
mailing list