Skip to content

[NFC][Clang][AST] Adopt simplified getTrailingObjects in AST #144432

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
Jun 19, 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
16 changes: 5 additions & 11 deletions clang/include/clang/AST/DeclTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,15 @@ class TemplateArgumentList final

/// Produce this as an array ref.
ArrayRef<TemplateArgument> asArray() const {
return llvm::ArrayRef(data(), size());
return getTrailingObjects(size());
}

/// Retrieve the number of template arguments in this
/// template argument list.
unsigned size() const { return NumArguments; }

/// Retrieve a pointer to the template argument list.
const TemplateArgument *data() const {
return getTrailingObjects<TemplateArgument>();
}
const TemplateArgument *data() const { return getTrailingObjects(); }
};

void *allocateDefaultArgStorageChain(const ASTContext &C);
Expand Down Expand Up @@ -505,12 +503,10 @@ class FunctionTemplateSpecializationInfo final
TemplateArgumentsAsWritten(TemplateArgsAsWritten),
PointOfInstantiation(POI) {
if (MSInfo)
getTrailingObjects<MemberSpecializationInfo *>()[0] = MSInfo;
getTrailingObjects()[0] = MSInfo;
}

size_t numTrailingObjects(OverloadToken<MemberSpecializationInfo*>) const {
return Function.getInt();
}
size_t numTrailingObjects() const { return Function.getInt(); }

public:
friend TrailingObjects;
Expand Down Expand Up @@ -597,9 +593,7 @@ class FunctionTemplateSpecializationInfo final
/// function and the function template, and should always be
/// TSK_ExplicitSpecialization whenever we have MemberSpecializationInfo.
MemberSpecializationInfo *getMemberSpecializationInfo() const {
return numTrailingObjects(OverloadToken<MemberSpecializationInfo *>())
? getTrailingObjects<MemberSpecializationInfo *>()[0]
: nullptr;
return numTrailingObjects() ? getTrailingObjects()[0] : nullptr;
}

void Profile(llvm::FoldingSetNodeID &ID) {
Expand Down
7 changes: 2 additions & 5 deletions clang/include/clang/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -7364,17 +7364,14 @@ class RecoveryExpr final : public Expr,
ArrayRef<Expr *> SubExprs);
static RecoveryExpr *CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs);

ArrayRef<Expr *> subExpressions() {
auto *B = getTrailingObjects<Expr *>();
return llvm::ArrayRef(B, B + NumExprs);
}
ArrayRef<Expr *> subExpressions() { return getTrailingObjects(NumExprs); }

ArrayRef<const Expr *> subExpressions() const {
return const_cast<RecoveryExpr *>(this)->subExpressions();
}

child_range children() {
Stmt **B = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
Stmt **B = reinterpret_cast<Stmt **>(getTrailingObjects());
return child_range(B, B + NumExprs);
}

Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/OpenACCClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class OpenACCDeviceTypeClause final
}

ArrayRef<DeviceTypeArgument> getArchitectures() const {
return getTrailingObjects<DeviceTypeArgument>(NumArchs);
return getTrailingObjects(NumArchs);
}

static OpenACCDeviceTypeClause *
Expand Down
42 changes: 11 additions & 31 deletions clang/include/clang/AST/OpenMPClause.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ template <class T> class OMPVarListClause : public OMPClause {
void setVarRefs(ArrayRef<Expr *> VL) {
assert(VL.size() == NumVars &&
"Number of variables is not the same as the preallocated buffer");
std::copy(VL.begin(), VL.end(),
static_cast<T *>(this)->template getTrailingObjects<Expr *>());
llvm::copy(VL, getVarRefs().begin());
}

public:
Expand Down Expand Up @@ -388,9 +387,7 @@ template <class T> class OMPDirectiveListClause : public OMPClause {
assert(
DK.size() == NumKinds &&
"Number of directive kinds is not the same as the preallocated buffer");
std::copy(DK.begin(), DK.end(),
static_cast<T *>(this)
->template getTrailingObjects<OpenMPDirectiveKind>());
std::copy(DK.begin(), DK.end(), getDirectiveKinds().begin());
}

SourceLocation getLParenLoc() { return LParenLoc; }
Expand Down Expand Up @@ -980,20 +977,14 @@ class OMPSizesClause final

/// Returns the tile size expressions.
MutableArrayRef<Expr *> getSizesRefs() {
return static_cast<OMPSizesClause *>(this)
->template getTrailingObjects<Expr *>(NumSizes);
}
ArrayRef<Expr *> getSizesRefs() const {
return static_cast<const OMPSizesClause *>(this)
->template getTrailingObjects<Expr *>(NumSizes);
return getTrailingObjects(NumSizes);
}
ArrayRef<Expr *> getSizesRefs() const { return getTrailingObjects(NumSizes); }

/// Sets the tile size expressions.
void setSizesRefs(ArrayRef<Expr *> VL) {
assert(VL.size() == NumSizes);
std::copy(VL.begin(), VL.end(),
static_cast<OMPSizesClause *>(this)
->template getTrailingObjects<Expr *>());
llvm::copy(VL, getSizesRefs().begin());
}

child_range children() {
Expand Down Expand Up @@ -1043,8 +1034,7 @@ class OMPPermutationClause final
/// Sets the permutation index expressions.
void setArgRefs(ArrayRef<Expr *> VL) {
assert(VL.size() == NumLoops && "Expecting one expression per loop");
llvm::copy(VL, static_cast<OMPPermutationClause *>(this)
->template getTrailingObjects<Expr *>());
llvm::copy(VL, getTrailingObjects());
}

/// Build an empty clause.
Expand Down Expand Up @@ -1083,14 +1073,8 @@ class OMPPermutationClause final

/// Returns the permutation index expressions.
///@{
MutableArrayRef<Expr *> getArgsRefs() {
return static_cast<OMPPermutationClause *>(this)
->template getTrailingObjects<Expr *>(NumLoops);
}
ArrayRef<Expr *> getArgsRefs() const {
return static_cast<const OMPPermutationClause *>(this)
->template getTrailingObjects<Expr *>(NumLoops);
}
MutableArrayRef<Expr *> getArgsRefs() { return getTrailingObjects(NumLoops); }
ArrayRef<Expr *> getArgsRefs() const { return getTrailingObjects(NumLoops); }
///@}

child_range children() {
Expand Down Expand Up @@ -9239,9 +9223,7 @@ class OMPAffinityClause final
SourceLocation(), N) {}

/// Sets the affinity modifier for the clause, if any.
void setModifier(Expr *E) {
getTrailingObjects<Expr *>()[varlist_size()] = E;
}
void setModifier(Expr *E) { getTrailingObjects()[varlist_size()] = E; }

/// Sets the location of ':' symbol.
void setColonLoc(SourceLocation Loc) { ColonLoc = Loc; }
Expand All @@ -9268,10 +9250,8 @@ class OMPAffinityClause final
static OMPAffinityClause *CreateEmpty(const ASTContext &C, unsigned N);

/// Gets affinity modifier.
Expr *getModifier() { return getTrailingObjects<Expr *>()[varlist_size()]; }
Expr *getModifier() const {
return getTrailingObjects<Expr *>()[varlist_size()];
}
Expr *getModifier() { return getTrailingObjects()[varlist_size()]; }
Expr *getModifier() const { return getTrailingObjects()[varlist_size()]; }

/// Gets the location of ':' symbol.
SourceLocation getColonLoc() const { return ColonLoc; }
Expand Down
2 changes: 1 addition & 1 deletion clang/include/clang/AST/StmtOpenACC.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ class OpenACCUpdateConstruct final
OpenACCDirectiveKind::Update, SourceLocation{},
SourceLocation{}, SourceLocation{}) {
std::uninitialized_value_construct_n(getTrailingObjects(), NumClauses);
setClauseList(getTrailingObjects<const OpenACCClause *>(NumClauses));
setClauseList(getTrailingObjects(NumClauses));
}

OpenACCUpdateConstruct(SourceLocation Start, SourceLocation DirectiveLoc,
Expand Down
6 changes: 2 additions & 4 deletions clang/include/clang/AST/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -6052,9 +6052,7 @@ class PackIndexingType final
ArrayRef<QualType> Expansions);

private:
const QualType *getExpansionsPtr() const {
return getTrailingObjects<QualType>();
}
const QualType *getExpansionsPtr() const { return getTrailingObjects(); }

static TypeDependence computeDependence(QualType Pattern, Expr *IndexExpr,
ArrayRef<QualType> Expansions = {});
Expand Down Expand Up @@ -6494,7 +6492,7 @@ class HLSLInlineSpirvType final
uint32_t getSize() const { return Size; }
uint32_t getAlignment() const { return Alignment; }
ArrayRef<SpirvOperand> getOperands() const {
return getTrailingObjects<SpirvOperand>(NumOperands);
return getTrailingObjects(NumOperands);
}

bool isSugared() const { return false; }
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/ASTImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4452,7 +4452,7 @@ ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) {
}

SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>();
auto **FromTPLists = D->getTrailingObjects();
for (unsigned I = 0; I < D->NumTPLists; I++) {
if (auto ListOrErr = import(FromTPLists[I]))
ToTPLists[I] = *ListOrErr;
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5380,7 +5380,7 @@ PragmaCommentDecl *PragmaCommentDecl::Create(const ASTContext &C,
new (C, DC, additionalSizeToAlloc<char>(Arg.size() + 1))
PragmaCommentDecl(DC, CommentLoc, CommentKind);
memcpy(PCD->getTrailingObjects(), Arg.data(), Arg.size());
PCD->getTrailingObjects<char>()[Arg.size()] = '\0';
PCD->getTrailingObjects()[Arg.size()] = '\0';
return PCD;
}

Expand Down
6 changes: 2 additions & 4 deletions clang/lib/AST/ExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,7 @@ CXXDynamicCastExpr *CXXDynamicCastExpr::Create(const ASTContext &C, QualType T,
new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
RParenLoc, AngleBrackets);
if (PathSize)
llvm::uninitialized_copy(*BasePath,
E->getTrailingObjects<CXXBaseSpecifier *>());
llvm::uninitialized_copy(*BasePath, E->getTrailingObjects());
return E;
}

Expand Down Expand Up @@ -869,8 +868,7 @@ CXXReinterpretCastExpr::Create(const ASTContext &C, QualType T,
new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
RParenLoc, AngleBrackets);
if (PathSize)
llvm::uninitialized_copy(*BasePath,
E->getTrailingObjects<CXXBaseSpecifier *>());
llvm::uninitialized_copy(*BasePath, E->getTrailingObjects());
return E;
}

Expand Down
12 changes: 6 additions & 6 deletions clang/lib/AST/OpenMPClause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,26 +370,26 @@ OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
Expr *NumIterations) {
assert(NumLoop < NumberOfLoops && "out of loops number.");
getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
getTrailingObjects()[NumLoop] = NumIterations;
}

ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
return getTrailingObjects<Expr *>(NumberOfLoops);
return getTrailingObjects(NumberOfLoops);
}

void OMPOrderedClause::setLoopCounter(unsigned NumLoop, Expr *Counter) {
assert(NumLoop < NumberOfLoops && "out of loops number.");
getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop] = Counter;
getTrailingObjects()[NumberOfLoops + NumLoop] = Counter;
}

Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) {
assert(NumLoop < NumberOfLoops && "out of loops number.");
return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
return getTrailingObjects()[NumberOfLoops + NumLoop];
}

const Expr *OMPOrderedClause::getLoopCounter(unsigned NumLoop) const {
assert(NumLoop < NumberOfLoops && "out of loops number.");
return getTrailingObjects<Expr *>()[NumberOfLoops + NumLoop];
return getTrailingObjects()[NumberOfLoops + NumLoop];
}

OMPUpdateClause *OMPUpdateClause::Create(const ASTContext &C,
Expand Down Expand Up @@ -1678,7 +1678,7 @@ OMPInitClause *OMPInitClause::Create(const ASTContext &C, Expr *InteropVar,
InteropInfo.IsTarget, InteropInfo.IsTargetSync, StartLoc, LParenLoc,
VarLoc, EndLoc, InteropInfo.PreferTypes.size() + 1);
Clause->setInteropVar(InteropVar);
llvm::copy(InteropInfo.PreferTypes, Clause->getTrailingObjects<Expr *>() + 1);
llvm::copy(InteropInfo.PreferTypes, Clause->getTrailingObjects() + 1);
return Clause;
}

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3981,7 +3981,7 @@ CountAttributedType::CountAttributedType(
CountAttributedTypeBits.NumCoupledDecls = CoupledDecls.size();
CountAttributedTypeBits.CountInBytes = CountInBytes;
CountAttributedTypeBits.OrNull = OrNull;
auto *DeclSlot = getTrailingObjects<TypeCoupledDeclRefInfo>();
auto *DeclSlot = getTrailingObjects();
Decls = llvm::ArrayRef(DeclSlot, CoupledDecls.size());
for (unsigned i = 0; i != CoupledDecls.size(); ++i)
DeclSlot[i] = CoupledDecls[i];
Expand Down
Loading