Skip to content

Commit 06aa28a

Browse files
jurahulTIFitis
authored andcommitted
[NFC][Clang] Adopt simplified getTrailingObjects in Decl/DeclTemplate (llvm#139977)
Adopt simplied `getTrailingObjects` variants that are not templated and/or return ArrayRef in Decl/DeclTemplate .h/.cpp files.
1 parent 518169a commit 06aa28a

File tree

4 files changed

+28
-45
lines changed

4 files changed

+28
-45
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class PragmaCommentDecl final
185185

186186
PragmaMSCommentKind getCommentKind() const { return CommentKind; }
187187

188-
StringRef getArg() const { return getTrailingObjects<char>(); }
188+
StringRef getArg() const { return getTrailingObjects(); }
189189

190190
// Implement isa/cast/dyncast/etc.
191191
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
@@ -217,8 +217,8 @@ class PragmaDetectMismatchDecl final
217217
static PragmaDetectMismatchDecl *
218218
CreateDeserialized(ASTContext &C, GlobalDeclID ID, unsigned NameValueSize);
219219

220-
StringRef getName() const { return getTrailingObjects<char>(); }
221-
StringRef getValue() const { return getTrailingObjects<char>() + ValueStart; }
220+
StringRef getName() const { return getTrailingObjects(); }
221+
StringRef getValue() const { return getTrailingObjects() + ValueStart; }
222222

223223
// Implement isa/cast/dyncast/etc.
224224
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
@@ -1991,7 +1991,7 @@ class FunctionDecl : public DeclaratorDecl,
19911991
/// Get the unqualified lookup results that should be used in this
19921992
/// defaulted function definition.
19931993
ArrayRef<DeclAccessPair> getUnqualifiedLookups() const {
1994-
return {getTrailingObjects<DeclAccessPair>(), NumLookups};
1994+
return getTrailingObjects<DeclAccessPair>(NumLookups);
19951995
}
19961996

19971997
StringLiteral *getDeletedMessage() const {
@@ -4780,13 +4780,9 @@ class OutlinedFunctionDecl final
47804780

47814781
explicit OutlinedFunctionDecl(DeclContext *DC, unsigned NumParams);
47824782

4783-
ImplicitParamDecl *const *getParams() const {
4784-
return getTrailingObjects<ImplicitParamDecl *>();
4785-
}
4783+
ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }
47864784

4787-
ImplicitParamDecl **getParams() {
4788-
return getTrailingObjects<ImplicitParamDecl *>();
4789-
}
4785+
ImplicitParamDecl **getParams() { return getTrailingObjects(); }
47904786

47914787
public:
47924788
friend class ASTDeclReader;
@@ -4857,13 +4853,9 @@ class CapturedDecl final
48574853

48584854
explicit CapturedDecl(DeclContext *DC, unsigned NumParams);
48594855

4860-
ImplicitParamDecl *const *getParams() const {
4861-
return getTrailingObjects<ImplicitParamDecl *>();
4862-
}
4856+
ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }
48634857

4864-
ImplicitParamDecl **getParams() {
4865-
return getTrailingObjects<ImplicitParamDecl *>();
4866-
}
4858+
ImplicitParamDecl **getParams() { return getTrailingObjects(); }
48674859

48684860
public:
48694861
friend class ASTDeclReader;
@@ -5187,12 +5179,10 @@ class HLSLRootSignatureDecl final
51875179

51885180
unsigned NumElems;
51895181

5190-
llvm::hlsl::rootsig::RootElement *getElems() {
5191-
return getTrailingObjects<llvm::hlsl::rootsig::RootElement>();
5192-
}
5182+
llvm::hlsl::rootsig::RootElement *getElems() { return getTrailingObjects(); }
51935183

51945184
const llvm::hlsl::rootsig::RootElement *getElems() const {
5195-
return getTrailingObjects<llvm::hlsl::rootsig::RootElement>();
5185+
return getTrailingObjects();
51965186
}
51975187

51985188
HLSLRootSignatureDecl(DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,

clang/include/clang/AST/DeclTemplate.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ class DependentFunctionTemplateSpecializationInfo final
712712

713713
/// Returns the candidates for the primary function template.
714714
ArrayRef<FunctionTemplateDecl *> getCandidates() const {
715-
return {getTrailingObjects<FunctionTemplateDecl *>(), NumCandidates};
715+
return getTrailingObjects(NumCandidates);
716716
}
717717
};
718718

@@ -1325,8 +1325,7 @@ class TemplateTypeParmDecl final : public TypeDecl,
13251325
/// Returns the type constraint associated with this template parameter (if
13261326
/// any).
13271327
const TypeConstraint *getTypeConstraint() const {
1328-
return TypeConstraintInitialized ? getTrailingObjects<TypeConstraint>() :
1329-
nullptr;
1328+
return TypeConstraintInitialized ? getTrailingObjects() : nullptr;
13301329
}
13311330

13321331
void setTypeConstraint(ConceptReference *CR,
@@ -1711,7 +1710,7 @@ class TemplateTemplateParmDecl final
17111710
/// pack.
17121711
TemplateParameterList *getExpansionTemplateParameters(unsigned I) const {
17131712
assert(I < NumExpandedParams && "Out-of-range expansion type index");
1714-
return getTrailingObjects<TemplateParameterList *>()[I];
1713+
return getTrailingObjects()[I];
17151714
}
17161715

17171716
const DefArgStorage &getDefaultArgStorage() const { return DefaultArgument; }
@@ -3254,8 +3253,7 @@ class ImplicitConceptSpecializationDecl final
32543253
unsigned NumTemplateArgs);
32553254

32563255
ArrayRef<TemplateArgument> getTemplateArguments() const {
3257-
return ArrayRef<TemplateArgument>(getTrailingObjects<TemplateArgument>(),
3258-
NumTemplateArgs);
3256+
return getTrailingObjects(NumTemplateArgs);
32593257
}
32603258
void setTemplateArguments(ArrayRef<TemplateArgument> Converted);
32613259

clang/lib/AST/Decl.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4325,8 +4325,7 @@ DependentFunctionTemplateSpecializationInfo::
43254325
const ASTTemplateArgumentListInfo *TemplateArgsWritten)
43264326
: NumCandidates(Candidates.size()),
43274327
TemplateArgumentsAsWritten(TemplateArgsWritten) {
4328-
std::transform(Candidates.begin(), Candidates.end(),
4329-
getTrailingObjects<FunctionTemplateDecl *>(),
4328+
std::transform(Candidates.begin(), Candidates.end(), getTrailingObjects(),
43304329
[](NamedDecl *ND) {
43314330
return cast<FunctionTemplateDecl>(ND->getUnderlyingDecl());
43324331
});
@@ -5380,7 +5379,7 @@ PragmaCommentDecl *PragmaCommentDecl::Create(const ASTContext &C,
53805379
PragmaCommentDecl *PCD =
53815380
new (C, DC, additionalSizeToAlloc<char>(Arg.size() + 1))
53825381
PragmaCommentDecl(DC, CommentLoc, CommentKind);
5383-
memcpy(PCD->getTrailingObjects<char>(), Arg.data(), Arg.size());
5382+
memcpy(PCD->getTrailingObjects(), Arg.data(), Arg.size());
53845383
PCD->getTrailingObjects<char>()[Arg.size()] = '\0';
53855384
return PCD;
53865385
}
@@ -5402,11 +5401,10 @@ PragmaDetectMismatchDecl::Create(const ASTContext &C, TranslationUnitDecl *DC,
54025401
PragmaDetectMismatchDecl *PDMD =
54035402
new (C, DC, additionalSizeToAlloc<char>(ValueStart + Value.size() + 1))
54045403
PragmaDetectMismatchDecl(DC, Loc, ValueStart);
5405-
memcpy(PDMD->getTrailingObjects<char>(), Name.data(), Name.size());
5406-
PDMD->getTrailingObjects<char>()[Name.size()] = '\0';
5407-
memcpy(PDMD->getTrailingObjects<char>() + ValueStart, Value.data(),
5408-
Value.size());
5409-
PDMD->getTrailingObjects<char>()[ValueStart + Value.size()] = '\0';
5404+
memcpy(PDMD->getTrailingObjects(), Name.data(), Name.size());
5405+
PDMD->getTrailingObjects()[Name.size()] = '\0';
5406+
memcpy(PDMD->getTrailingObjects() + ValueStart, Value.data(), Value.size());
5407+
PDMD->getTrailingObjects()[ValueStart + Value.size()] = '\0';
54105408
return PDMD;
54115409
}
54125410

@@ -5900,15 +5898,15 @@ ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
59005898
: Decl(Import, DC, StartLoc), ImportedModule(Imported),
59015899
NextLocalImportAndComplete(nullptr, true) {
59025900
assert(getNumModuleIdentifiers(Imported) == IdentifierLocs.size());
5903-
auto *StoredLocs = getTrailingObjects<SourceLocation>();
5901+
auto *StoredLocs = getTrailingObjects();
59045902
llvm::uninitialized_copy(IdentifierLocs, StoredLocs);
59055903
}
59065904

59075905
ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
59085906
Module *Imported, SourceLocation EndLoc)
59095907
: Decl(Import, DC, StartLoc), ImportedModule(Imported),
59105908
NextLocalImportAndComplete(nullptr, false) {
5911-
*getTrailingObjects<SourceLocation>() = EndLoc;
5909+
*getTrailingObjects() = EndLoc;
59125910
}
59135911

59145912
ImportDecl *ImportDecl::Create(ASTContext &C, DeclContext *DC,
@@ -5939,14 +5937,12 @@ ArrayRef<SourceLocation> ImportDecl::getIdentifierLocs() const {
59395937
if (!isImportComplete())
59405938
return {};
59415939

5942-
const auto *StoredLocs = getTrailingObjects<SourceLocation>();
5943-
return llvm::ArrayRef(StoredLocs,
5944-
getNumModuleIdentifiers(getImportedModule()));
5940+
return getTrailingObjects(getNumModuleIdentifiers(getImportedModule()));
59455941
}
59465942

59475943
SourceRange ImportDecl::getSourceRange() const {
59485944
if (!isImportComplete())
5949-
return SourceRange(getLocation(), *getTrailingObjects<SourceLocation>());
5945+
return SourceRange(getLocation(), *getTrailingObjects());
59505946

59515947
return SourceRange(getLocation(), getIdentifierLocs().back());
59525948
}

clang/lib/AST/DeclTemplate.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ void TemplateTypeParmDecl::setTypeConstraint(
755755
"call setTypeConstraint");
756756
assert(!TypeConstraintInitialized &&
757757
"TypeConstraint was already initialized!");
758-
new (getTrailingObjects<TypeConstraint>())
758+
new (getTrailingObjects())
759759
TypeConstraint(Loc, ImmediatelyDeclaredConstraint, ArgPackSubstIndex);
760760
TypeConstraintInitialized = true;
761761
}
@@ -880,8 +880,7 @@ TemplateTemplateParmDecl::TemplateTemplateParmDecl(
880880
: TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
881881
TemplateParmPosition(D, P), Typename(Typename), ParameterPack(true),
882882
ExpandedParameterPack(true), NumExpandedParams(Expansions.size()) {
883-
llvm::uninitialized_copy(Expansions,
884-
getTrailingObjects<TemplateParameterList *>());
883+
llvm::uninitialized_copy(Expansions, getTrailingObjects());
885884
}
886885

887886
TemplateTemplateParmDecl *
@@ -939,7 +938,7 @@ void TemplateTemplateParmDecl::setDefaultArgument(
939938
//===----------------------------------------------------------------------===//
940939
TemplateArgumentList::TemplateArgumentList(ArrayRef<TemplateArgument> Args)
941940
: NumArguments(Args.size()) {
942-
llvm::uninitialized_copy(Args, getTrailingObjects<TemplateArgument>());
941+
llvm::uninitialized_copy(Args, getTrailingObjects());
943942
}
944943

945944
TemplateArgumentList *
@@ -1166,7 +1165,7 @@ ImplicitConceptSpecializationDecl::CreateDeserialized(
11661165
void ImplicitConceptSpecializationDecl::setTemplateArguments(
11671166
ArrayRef<TemplateArgument> Converted) {
11681167
assert(Converted.size() == NumTemplateArgs);
1169-
llvm::uninitialized_copy(Converted, getTrailingObjects<TemplateArgument>());
1168+
llvm::uninitialized_copy(Converted, getTrailingObjects());
11701169
}
11711170

11721171
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)