Skip to content

Commit 5cf7d87

Browse files
authored
[NFC][Clang][AST] Adopt simplified getTrailingObjects in AST (#144432)
Adopt simplified `getTrailingObjects` API in several places in clag/AST that were missed by earlier changes.
1 parent b833734 commit 5cf7d87

File tree

11 files changed

+33
-66
lines changed

11 files changed

+33
-66
lines changed

clang/include/clang/AST/DeclTemplate.h

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,15 @@ class TemplateArgumentList final
279279

280280
/// Produce this as an array ref.
281281
ArrayRef<TemplateArgument> asArray() const {
282-
return llvm::ArrayRef(data(), size());
282+
return getTrailingObjects(size());
283283
}
284284

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

289289
/// Retrieve a pointer to the template argument list.
290-
const TemplateArgument *data() const {
291-
return getTrailingObjects<TemplateArgument>();
292-
}
290+
const TemplateArgument *data() const { return getTrailingObjects(); }
293291
};
294292

295293
void *allocateDefaultArgStorageChain(const ASTContext &C);
@@ -505,12 +503,10 @@ class FunctionTemplateSpecializationInfo final
505503
TemplateArgumentsAsWritten(TemplateArgsAsWritten),
506504
PointOfInstantiation(POI) {
507505
if (MSInfo)
508-
getTrailingObjects<MemberSpecializationInfo *>()[0] = MSInfo;
506+
getTrailingObjects()[0] = MSInfo;
509507
}
510508

511-
size_t numTrailingObjects(OverloadToken<MemberSpecializationInfo*>) const {
512-
return Function.getInt();
513-
}
509+
size_t numTrailingObjects() const { return Function.getInt(); }
514510

515511
public:
516512
friend TrailingObjects;
@@ -597,9 +593,7 @@ class FunctionTemplateSpecializationInfo final
597593
/// function and the function template, and should always be
598594
/// TSK_ExplicitSpecialization whenever we have MemberSpecializationInfo.
599595
MemberSpecializationInfo *getMemberSpecializationInfo() const {
600-
return numTrailingObjects(OverloadToken<MemberSpecializationInfo *>())
601-
? getTrailingObjects<MemberSpecializationInfo *>()[0]
602-
: nullptr;
596+
return numTrailingObjects() ? getTrailingObjects()[0] : nullptr;
603597
}
604598

605599
void Profile(llvm::FoldingSetNodeID &ID) {

clang/include/clang/AST/Expr.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7364,17 +7364,14 @@ class RecoveryExpr final : public Expr,
73647364
ArrayRef<Expr *> SubExprs);
73657365
static RecoveryExpr *CreateEmpty(ASTContext &Ctx, unsigned NumSubExprs);
73667366

7367-
ArrayRef<Expr *> subExpressions() {
7368-
auto *B = getTrailingObjects<Expr *>();
7369-
return llvm::ArrayRef(B, B + NumExprs);
7370-
}
7367+
ArrayRef<Expr *> subExpressions() { return getTrailingObjects(NumExprs); }
73717368

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

73767373
child_range children() {
7377-
Stmt **B = reinterpret_cast<Stmt **>(getTrailingObjects<Expr *>());
7374+
Stmt **B = reinterpret_cast<Stmt **>(getTrailingObjects());
73787375
return child_range(B, B + NumExprs);
73797376
}
73807377

clang/include/clang/AST/OpenACCClause.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class OpenACCDeviceTypeClause final
307307
}
308308

309309
ArrayRef<DeviceTypeArgument> getArchitectures() const {
310-
return getTrailingObjects<DeviceTypeArgument>(NumArchs);
310+
return getTrailingObjects(NumArchs);
311311
}
312312

313313
static OpenACCDeviceTypeClause *

clang/include/clang/AST/OpenMPClause.h

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ template <class T> class OMPVarListClause : public OMPClause {
302302
void setVarRefs(ArrayRef<Expr *> VL) {
303303
assert(VL.size() == NumVars &&
304304
"Number of variables is not the same as the preallocated buffer");
305-
std::copy(VL.begin(), VL.end(),
306-
static_cast<T *>(this)->template getTrailingObjects<Expr *>());
305+
llvm::copy(VL, getVarRefs().begin());
307306
}
308307

309308
public:
@@ -388,9 +387,7 @@ template <class T> class OMPDirectiveListClause : public OMPClause {
388387
assert(
389388
DK.size() == NumKinds &&
390389
"Number of directive kinds is not the same as the preallocated buffer");
391-
std::copy(DK.begin(), DK.end(),
392-
static_cast<T *>(this)
393-
->template getTrailingObjects<OpenMPDirectiveKind>());
390+
std::copy(DK.begin(), DK.end(), getDirectiveKinds().begin());
394391
}
395392

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

981978
/// Returns the tile size expressions.
982979
MutableArrayRef<Expr *> getSizesRefs() {
983-
return static_cast<OMPSizesClause *>(this)
984-
->template getTrailingObjects<Expr *>(NumSizes);
985-
}
986-
ArrayRef<Expr *> getSizesRefs() const {
987-
return static_cast<const OMPSizesClause *>(this)
988-
->template getTrailingObjects<Expr *>(NumSizes);
980+
return getTrailingObjects(NumSizes);
989981
}
982+
ArrayRef<Expr *> getSizesRefs() const { return getTrailingObjects(NumSizes); }
990983

991984
/// Sets the tile size expressions.
992985
void setSizesRefs(ArrayRef<Expr *> VL) {
993986
assert(VL.size() == NumSizes);
994-
std::copy(VL.begin(), VL.end(),
995-
static_cast<OMPSizesClause *>(this)
996-
->template getTrailingObjects<Expr *>());
987+
llvm::copy(VL, getSizesRefs().begin());
997988
}
998989

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

10501040
/// Build an empty clause.
@@ -1083,14 +1073,8 @@ class OMPPermutationClause final
10831073

10841074
/// Returns the permutation index expressions.
10851075
///@{
1086-
MutableArrayRef<Expr *> getArgsRefs() {
1087-
return static_cast<OMPPermutationClause *>(this)
1088-
->template getTrailingObjects<Expr *>(NumLoops);
1089-
}
1090-
ArrayRef<Expr *> getArgsRefs() const {
1091-
return static_cast<const OMPPermutationClause *>(this)
1092-
->template getTrailingObjects<Expr *>(NumLoops);
1093-
}
1076+
MutableArrayRef<Expr *> getArgsRefs() { return getTrailingObjects(NumLoops); }
1077+
ArrayRef<Expr *> getArgsRefs() const { return getTrailingObjects(NumLoops); }
10941078
///@}
10951079

10961080
child_range children() {
@@ -9239,9 +9223,7 @@ class OMPAffinityClause final
92399223
SourceLocation(), N) {}
92409224

92419225
/// Sets the affinity modifier for the clause, if any.
9242-
void setModifier(Expr *E) {
9243-
getTrailingObjects<Expr *>()[varlist_size()] = E;
9244-
}
9226+
void setModifier(Expr *E) { getTrailingObjects()[varlist_size()] = E; }
92459227

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

92709252
/// Gets affinity modifier.
9271-
Expr *getModifier() { return getTrailingObjects<Expr *>()[varlist_size()]; }
9272-
Expr *getModifier() const {
9273-
return getTrailingObjects<Expr *>()[varlist_size()];
9274-
}
9253+
Expr *getModifier() { return getTrailingObjects()[varlist_size()]; }
9254+
Expr *getModifier() const { return getTrailingObjects()[varlist_size()]; }
92759255

92769256
/// Gets the location of ':' symbol.
92779257
SourceLocation getColonLoc() const { return ColonLoc; }

clang/include/clang/AST/StmtOpenACC.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ class OpenACCUpdateConstruct final
736736
OpenACCDirectiveKind::Update, SourceLocation{},
737737
SourceLocation{}, SourceLocation{}) {
738738
std::uninitialized_value_construct_n(getTrailingObjects(), NumClauses);
739-
setClauseList(getTrailingObjects<const OpenACCClause *>(NumClauses));
739+
setClauseList(getTrailingObjects(NumClauses));
740740
}
741741

742742
OpenACCUpdateConstruct(SourceLocation Start, SourceLocation DirectiveLoc,

clang/include/clang/AST/Type.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6052,9 +6052,7 @@ class PackIndexingType final
60526052
ArrayRef<QualType> Expansions);
60536053

60546054
private:
6055-
const QualType *getExpansionsPtr() const {
6056-
return getTrailingObjects<QualType>();
6057-
}
6055+
const QualType *getExpansionsPtr() const { return getTrailingObjects(); }
60586056

60596057
static TypeDependence computeDependence(QualType Pattern, Expr *IndexExpr,
60606058
ArrayRef<QualType> Expansions = {});
@@ -6494,7 +6492,7 @@ class HLSLInlineSpirvType final
64946492
uint32_t getSize() const { return Size; }
64956493
uint32_t getAlignment() const { return Alignment; }
64966494
ArrayRef<SpirvOperand> getOperands() const {
6497-
return getTrailingObjects<SpirvOperand>(NumOperands);
6495+
return getTrailingObjects(NumOperands);
64986496
}
64996497

65006498
bool isSugared() const { return false; }

clang/lib/AST/ASTImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4452,7 +4452,7 @@ ExpectedDecl ASTNodeImporter::VisitFriendDecl(FriendDecl *D) {
44524452
}
44534453

44544454
SmallVector<TemplateParameterList *, 1> ToTPLists(D->NumTPLists);
4455-
auto **FromTPLists = D->getTrailingObjects<TemplateParameterList *>();
4455+
auto **FromTPLists = D->getTrailingObjects();
44564456
for (unsigned I = 0; I < D->NumTPLists; I++) {
44574457
if (auto ListOrErr = import(FromTPLists[I]))
44584458
ToTPLists[I] = *ListOrErr;

clang/lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5380,7 +5380,7 @@ PragmaCommentDecl *PragmaCommentDecl::Create(const ASTContext &C,
53805380
new (C, DC, additionalSizeToAlloc<char>(Arg.size() + 1))
53815381
PragmaCommentDecl(DC, CommentLoc, CommentKind);
53825382
memcpy(PCD->getTrailingObjects(), Arg.data(), Arg.size());
5383-
PCD->getTrailingObjects<char>()[Arg.size()] = '\0';
5383+
PCD->getTrailingObjects()[Arg.size()] = '\0';
53845384
return PCD;
53855385
}
53865386

clang/lib/AST/ExprCXX.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,8 +806,7 @@ CXXDynamicCastExpr *CXXDynamicCastExpr::Create(const ASTContext &C, QualType T,
806806
new (Buffer) CXXDynamicCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
807807
RParenLoc, AngleBrackets);
808808
if (PathSize)
809-
llvm::uninitialized_copy(*BasePath,
810-
E->getTrailingObjects<CXXBaseSpecifier *>());
809+
llvm::uninitialized_copy(*BasePath, E->getTrailingObjects());
811810
return E;
812811
}
813812

@@ -869,8 +868,7 @@ CXXReinterpretCastExpr::Create(const ASTContext &C, QualType T,
869868
new (Buffer) CXXReinterpretCastExpr(T, VK, K, Op, PathSize, WrittenTy, L,
870869
RParenLoc, AngleBrackets);
871870
if (PathSize)
872-
llvm::uninitialized_copy(*BasePath,
873-
E->getTrailingObjects<CXXBaseSpecifier *>());
871+
llvm::uninitialized_copy(*BasePath, E->getTrailingObjects());
874872
return E;
875873
}
876874

clang/lib/AST/OpenMPClause.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,26 +370,26 @@ OMPOrderedClause *OMPOrderedClause::CreateEmpty(const ASTContext &C,
370370
void OMPOrderedClause::setLoopNumIterations(unsigned NumLoop,
371371
Expr *NumIterations) {
372372
assert(NumLoop < NumberOfLoops && "out of loops number.");
373-
getTrailingObjects<Expr *>()[NumLoop] = NumIterations;
373+
getTrailingObjects()[NumLoop] = NumIterations;
374374
}
375375

376376
ArrayRef<Expr *> OMPOrderedClause::getLoopNumIterations() const {
377-
return getTrailingObjects<Expr *>(NumberOfLoops);
377+
return getTrailingObjects(NumberOfLoops);
378378
}
379379

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

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

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

395395
OMPUpdateClause *OMPUpdateClause::Create(const ASTContext &C,
@@ -1678,7 +1678,7 @@ OMPInitClause *OMPInitClause::Create(const ASTContext &C, Expr *InteropVar,
16781678
InteropInfo.IsTarget, InteropInfo.IsTargetSync, StartLoc, LParenLoc,
16791679
VarLoc, EndLoc, InteropInfo.PreferTypes.size() + 1);
16801680
Clause->setInteropVar(InteropVar);
1681-
llvm::copy(InteropInfo.PreferTypes, Clause->getTrailingObjects<Expr *>() + 1);
1681+
llvm::copy(InteropInfo.PreferTypes, Clause->getTrailingObjects() + 1);
16821682
return Clause;
16831683
}
16841684

clang/lib/AST/Type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3981,7 +3981,7 @@ CountAttributedType::CountAttributedType(
39813981
CountAttributedTypeBits.NumCoupledDecls = CoupledDecls.size();
39823982
CountAttributedTypeBits.CountInBytes = CountInBytes;
39833983
CountAttributedTypeBits.OrNull = OrNull;
3984-
auto *DeclSlot = getTrailingObjects<TypeCoupledDeclRefInfo>();
3984+
auto *DeclSlot = getTrailingObjects();
39853985
Decls = llvm::ArrayRef(DeclSlot, CoupledDecls.size());
39863986
for (unsigned i = 0; i != CoupledDecls.size(); ++i)
39873987
DeclSlot[i] = CoupledDecls[i];

0 commit comments

Comments
 (0)