[clang] 59f8af3 - [NFC][Clang] Adopt simplified `getTrailingObjects` in DeclFriend (#140081)
via cfe-commits
cfe-commits at lists.llvm.org
Mon May 19 08:02:28 PDT 2025
Author: Rahul Joshi
Date: 2025-05-19T08:02:23-07:00
New Revision: 59f8af35b6bb15c0794873786cb34c7867be357b
URL: https://github.com/llvm/llvm-project/commit/59f8af35b6bb15c0794873786cb34c7867be357b
DIFF: https://github.com/llvm/llvm-project/commit/59f8af35b6bb15c0794873786cb34c7867be357b.diff
LOG: [NFC][Clang] Adopt simplified `getTrailingObjects` in DeclFriend (#140081)
- Adopt non-templated `getTrailingObjects` in DeclFriend, DeclGroup, and
DeclObjC
- Use indexing into ArrayRef returned by `getTrailingObjects` and
eliminate explicit OOB asserts.
Added:
Modified:
clang/include/clang/AST/DeclFriend.h
clang/include/clang/AST/DeclGroup.h
clang/include/clang/AST/DeclObjC.h
clang/lib/AST/DeclGroup.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/DeclFriend.h b/clang/include/clang/AST/DeclFriend.h
index 1578580c89cd8..1644e2de98f80 100644
--- a/clang/include/clang/AST/DeclFriend.h
+++ b/clang/include/clang/AST/DeclFriend.h
@@ -90,8 +90,7 @@ class FriendDecl final
: Decl(Decl::Friend, DC, L), Friend(Friend), FriendLoc(FriendL),
EllipsisLoc(EllipsisLoc), UnsupportedFriend(false),
NumTPLists(FriendTypeTPLists.size()) {
- for (unsigned i = 0; i < NumTPLists; ++i)
- getTrailingObjects<TemplateParameterList *>()[i] = FriendTypeTPLists[i];
+ llvm::copy(FriendTypeTPLists, getTrailingObjects());
}
FriendDecl(EmptyShell Empty, unsigned NumFriendTypeTPLists)
@@ -132,8 +131,7 @@ class FriendDecl final
}
TemplateParameterList *getFriendTypeTemplateParameterList(unsigned N) const {
- assert(N < NumTPLists);
- return getTrailingObjects<TemplateParameterList *>()[N];
+ return getTrailingObjects(NumTPLists)[N];
}
/// If this friend declaration doesn't name a type, return the inner
@@ -153,10 +151,9 @@ class FriendDecl final
/// Retrieves the source range for the friend declaration.
SourceRange getSourceRange() const override LLVM_READONLY {
if (TypeSourceInfo *TInfo = getFriendType()) {
- SourceLocation StartL =
- (NumTPLists == 0) ? getFriendLoc()
- : getTrailingObjects<TemplateParameterList *>()[0]
- ->getTemplateLoc();
+ SourceLocation StartL = (NumTPLists == 0)
+ ? getFriendLoc()
+ : getTrailingObjects()[0]->getTemplateLoc();
SourceLocation EndL = isPackExpansion() ? getEllipsisLoc()
: TInfo->getTypeLoc().getEndLoc();
return SourceRange(StartL, EndL);
diff --git a/clang/include/clang/AST/DeclGroup.h b/clang/include/clang/AST/DeclGroup.h
index 672b7b0a9fe22..6637599f0cd0c 100644
--- a/clang/include/clang/AST/DeclGroup.h
+++ b/clang/include/clang/AST/DeclGroup.h
@@ -37,14 +37,10 @@ class DeclGroup final : private llvm::TrailingObjects<DeclGroup, Decl *> {
unsigned size() const { return NumDecls; }
- Decl*& operator[](unsigned i) {
- assert (i < NumDecls && "Out-of-bounds access.");
- return getTrailingObjects<Decl *>()[i];
- }
+ Decl *&operator[](unsigned i) { return getTrailingObjects(NumDecls)[i]; }
Decl* const& operator[](unsigned i) const {
- assert (i < NumDecls && "Out-of-bounds access.");
- return getTrailingObjects<Decl *>()[i];
+ return getTrailingObjects(NumDecls)[i];
}
};
diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h
index 4663603f79754..6e582627c45ed 100644
--- a/clang/include/clang/AST/DeclObjC.h
+++ b/clang/include/clang/AST/DeclObjC.h
@@ -678,7 +678,7 @@ class ObjCTypeParamList final
/// Iterate through the type parameters in the list.
using iterator = ObjCTypeParamDecl **;
- iterator begin() { return getTrailingObjects<ObjCTypeParamDecl *>(); }
+ iterator begin() { return getTrailingObjects(); }
iterator end() { return begin() + size(); }
@@ -688,9 +688,7 @@ class ObjCTypeParamList final
// Iterate through the type parameters in the list.
using const_iterator = ObjCTypeParamDecl * const *;
- const_iterator begin() const {
- return getTrailingObjects<ObjCTypeParamDecl *>();
- }
+ const_iterator begin() const { return getTrailingObjects(); }
const_iterator end() const {
return begin() + size();
diff --git a/clang/lib/AST/DeclGroup.cpp b/clang/lib/AST/DeclGroup.cpp
index 27dbdaab6f30d..fad52ff6e1d3b 100644
--- a/clang/lib/AST/DeclGroup.cpp
+++ b/clang/lib/AST/DeclGroup.cpp
@@ -28,6 +28,5 @@ DeclGroup* DeclGroup::Create(ASTContext &C, Decl **Decls, unsigned NumDecls) {
DeclGroup::DeclGroup(unsigned numdecls, Decl** decls) : NumDecls(numdecls) {
assert(numdecls > 0);
assert(decls);
- std::uninitialized_copy(decls, decls + numdecls,
- getTrailingObjects<Decl *>());
+ std::uninitialized_copy(decls, decls + numdecls, getTrailingObjects());
}
More information about the cfe-commits
mailing list