Skip to content

[NFC][Clang] Adopt simplified getTrailingObjects in Decl/DeclTemplate #139977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class PragmaCommentDecl final

PragmaMSCommentKind getCommentKind() const { return CommentKind; }

StringRef getArg() const { return getTrailingObjects<char>(); }
StringRef getArg() const { return getTrailingObjects(); }

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

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

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

StringLiteral *getDeletedMessage() const {
Expand Down Expand Up @@ -4780,13 +4780,9 @@ class OutlinedFunctionDecl final

explicit OutlinedFunctionDecl(DeclContext *DC, unsigned NumParams);

ImplicitParamDecl *const *getParams() const {
return getTrailingObjects<ImplicitParamDecl *>();
}
ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }

ImplicitParamDecl **getParams() {
return getTrailingObjects<ImplicitParamDecl *>();
}
ImplicitParamDecl **getParams() { return getTrailingObjects(); }

public:
friend class ASTDeclReader;
Expand Down Expand Up @@ -4857,13 +4853,9 @@ class CapturedDecl final

explicit CapturedDecl(DeclContext *DC, unsigned NumParams);

ImplicitParamDecl *const *getParams() const {
return getTrailingObjects<ImplicitParamDecl *>();
}
ImplicitParamDecl *const *getParams() const { return getTrailingObjects(); }

ImplicitParamDecl **getParams() {
return getTrailingObjects<ImplicitParamDecl *>();
}
ImplicitParamDecl **getParams() { return getTrailingObjects(); }

public:
friend class ASTDeclReader;
Expand Down Expand Up @@ -5187,12 +5179,10 @@ class HLSLRootSignatureDecl final

unsigned NumElems;

llvm::hlsl::rootsig::RootElement *getElems() {
return getTrailingObjects<llvm::hlsl::rootsig::RootElement>();
}
llvm::hlsl::rootsig::RootElement *getElems() { return getTrailingObjects(); }

const llvm::hlsl::rootsig::RootElement *getElems() const {
return getTrailingObjects<llvm::hlsl::rootsig::RootElement>();
return getTrailingObjects();
}

HLSLRootSignatureDecl(DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
Expand Down
10 changes: 4 additions & 6 deletions clang/include/clang/AST/DeclTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ class DependentFunctionTemplateSpecializationInfo final

/// Returns the candidates for the primary function template.
ArrayRef<FunctionTemplateDecl *> getCandidates() const {
return {getTrailingObjects<FunctionTemplateDecl *>(), NumCandidates};
return getTrailingObjects(NumCandidates);
}
};

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

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

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

ArrayRef<TemplateArgument> getTemplateArguments() const {
return ArrayRef<TemplateArgument>(getTrailingObjects<TemplateArgument>(),
NumTemplateArgs);
return getTrailingObjects(NumTemplateArgs);
}
void setTemplateArguments(ArrayRef<TemplateArgument> Converted);

Expand Down
24 changes: 10 additions & 14 deletions clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4325,8 +4325,7 @@ DependentFunctionTemplateSpecializationInfo::
const ASTTemplateArgumentListInfo *TemplateArgsWritten)
: NumCandidates(Candidates.size()),
TemplateArgumentsAsWritten(TemplateArgsWritten) {
std::transform(Candidates.begin(), Candidates.end(),
getTrailingObjects<FunctionTemplateDecl *>(),
std::transform(Candidates.begin(), Candidates.end(), getTrailingObjects(),
[](NamedDecl *ND) {
return cast<FunctionTemplateDecl>(ND->getUnderlyingDecl());
});
Expand Down Expand Up @@ -5380,7 +5379,7 @@ PragmaCommentDecl *PragmaCommentDecl::Create(const ASTContext &C,
PragmaCommentDecl *PCD =
new (C, DC, additionalSizeToAlloc<char>(Arg.size() + 1))
PragmaCommentDecl(DC, CommentLoc, CommentKind);
memcpy(PCD->getTrailingObjects<char>(), Arg.data(), Arg.size());
memcpy(PCD->getTrailingObjects(), Arg.data(), Arg.size());
PCD->getTrailingObjects<char>()[Arg.size()] = '\0';
return PCD;
}
Expand All @@ -5402,11 +5401,10 @@ PragmaDetectMismatchDecl::Create(const ASTContext &C, TranslationUnitDecl *DC,
PragmaDetectMismatchDecl *PDMD =
new (C, DC, additionalSizeToAlloc<char>(ValueStart + Value.size() + 1))
PragmaDetectMismatchDecl(DC, Loc, ValueStart);
memcpy(PDMD->getTrailingObjects<char>(), Name.data(), Name.size());
PDMD->getTrailingObjects<char>()[Name.size()] = '\0';
memcpy(PDMD->getTrailingObjects<char>() + ValueStart, Value.data(),
Value.size());
PDMD->getTrailingObjects<char>()[ValueStart + Value.size()] = '\0';
memcpy(PDMD->getTrailingObjects(), Name.data(), Name.size());
PDMD->getTrailingObjects()[Name.size()] = '\0';
memcpy(PDMD->getTrailingObjects() + ValueStart, Value.data(), Value.size());
PDMD->getTrailingObjects()[ValueStart + Value.size()] = '\0';
return PDMD;
}

Expand Down Expand Up @@ -5900,15 +5898,15 @@ ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
: Decl(Import, DC, StartLoc), ImportedModule(Imported),
NextLocalImportAndComplete(nullptr, true) {
assert(getNumModuleIdentifiers(Imported) == IdentifierLocs.size());
auto *StoredLocs = getTrailingObjects<SourceLocation>();
auto *StoredLocs = getTrailingObjects();
llvm::uninitialized_copy(IdentifierLocs, StoredLocs);
}

ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
Module *Imported, SourceLocation EndLoc)
: Decl(Import, DC, StartLoc), ImportedModule(Imported),
NextLocalImportAndComplete(nullptr, false) {
*getTrailingObjects<SourceLocation>() = EndLoc;
*getTrailingObjects() = EndLoc;
}

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

const auto *StoredLocs = getTrailingObjects<SourceLocation>();
return llvm::ArrayRef(StoredLocs,
getNumModuleIdentifiers(getImportedModule()));
return getTrailingObjects(getNumModuleIdentifiers(getImportedModule()));
}

SourceRange ImportDecl::getSourceRange() const {
if (!isImportComplete())
return SourceRange(getLocation(), *getTrailingObjects<SourceLocation>());
return SourceRange(getLocation(), *getTrailingObjects());

return SourceRange(getLocation(), getIdentifierLocs().back());
}
Expand Down
9 changes: 4 additions & 5 deletions clang/lib/AST/DeclTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ void TemplateTypeParmDecl::setTypeConstraint(
"call setTypeConstraint");
assert(!TypeConstraintInitialized &&
"TypeConstraint was already initialized!");
new (getTrailingObjects<TypeConstraint>())
new (getTrailingObjects())
TypeConstraint(Loc, ImmediatelyDeclaredConstraint, ArgPackSubstIndex);
TypeConstraintInitialized = true;
}
Expand Down Expand Up @@ -880,8 +880,7 @@ TemplateTemplateParmDecl::TemplateTemplateParmDecl(
: TemplateDecl(TemplateTemplateParm, DC, L, Id, Params),
TemplateParmPosition(D, P), Typename(Typename), ParameterPack(true),
ExpandedParameterPack(true), NumExpandedParams(Expansions.size()) {
llvm::uninitialized_copy(Expansions,
getTrailingObjects<TemplateParameterList *>());
llvm::uninitialized_copy(Expansions, getTrailingObjects());
}

TemplateTemplateParmDecl *
Expand Down Expand Up @@ -939,7 +938,7 @@ void TemplateTemplateParmDecl::setDefaultArgument(
//===----------------------------------------------------------------------===//
TemplateArgumentList::TemplateArgumentList(ArrayRef<TemplateArgument> Args)
: NumArguments(Args.size()) {
llvm::uninitialized_copy(Args, getTrailingObjects<TemplateArgument>());
llvm::uninitialized_copy(Args, getTrailingObjects());
}

TemplateArgumentList *
Expand Down Expand Up @@ -1166,7 +1165,7 @@ ImplicitConceptSpecializationDecl::CreateDeserialized(
void ImplicitConceptSpecializationDecl::setTemplateArguments(
ArrayRef<TemplateArgument> Converted) {
assert(Converted.size() == NumTemplateArgs);
llvm::uninitialized_copy(Converted, getTrailingObjects<TemplateArgument>());
llvm::uninitialized_copy(Converted, getTrailingObjects());
}

//===----------------------------------------------------------------------===//
Expand Down