Skip to content

Commit c047870

Browse files
[AST] Explicitly cast uint64_t to size_t for 32-bit platforms
There are a few places in the AST where we use `uint64_t` as `ArrayRef`'s size type. Even though of these `uint64_t` size fields are actually defined as bitfields with a maximum value of 32, but unfortunately it's not taken into account and clang complains about the implicit cast. The same attempt was made in 073905b, but several new places were added since then.
1 parent 772cff1 commit c047870

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

include/swift/AST/Attr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2962,7 +2962,7 @@ class AllowFeatureSuppressionAttr final
29622962

29632963
ArrayRef<Identifier> getSuppressedFeatures() const {
29642964
return {getTrailingObjects<Identifier>(),
2965-
Bits.AllowFeatureSuppressionAttr.NumFeatures};
2965+
static_cast<size_t>(Bits.AllowFeatureSuppressionAttr.NumFeatures)};
29662966
}
29672967

29682968
static bool classof(const DeclAttribute *DA) {

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8672,7 +8672,7 @@ class EnumCaseDecl final : public Decl,
86728672
/// Get the list of elements declared in this case.
86738673
ArrayRef<EnumElementDecl *> getElements() const {
86748674
return {getTrailingObjects<EnumElementDecl *>(),
8675-
Bits.EnumCaseDecl.NumElements};
8675+
static_cast<size_t>(Bits.EnumCaseDecl.NumElements)};
86768676
}
86778677
SourceRange getSourceRange() const;
86788678

include/swift/AST/Expr.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,10 +2453,10 @@ class CollectionExpr : public Expr {
24532453

24542454
/// Retrieve the elements stored in the collection.
24552455
ArrayRef<Expr *> getElements() const {
2456-
return {getTrailingObjectsPointer(), Bits.CollectionExpr.NumSubExprs};
2456+
return {getTrailingObjectsPointer(), static_cast<size_t>(Bits.CollectionExpr.NumSubExprs)};
24572457
}
24582458
MutableArrayRef<Expr *> getElements() {
2459-
return {getTrailingObjectsPointer(), Bits.CollectionExpr.NumSubExprs};
2459+
return {getTrailingObjectsPointer(), static_cast<size_t>(Bits.CollectionExpr.NumSubExprs)};
24602460
}
24612461
Expr *getElement(unsigned i) const { return getElements()[i]; }
24622462
void setElement(unsigned i, Expr *E) { getElements()[i] = E; }
@@ -3517,7 +3517,7 @@ class ErasureExpr final : public ImplicitConversionExpr,
35173517
/// that corresponding protocol).
35183518
ArrayRef<ProtocolConformanceRef> getConformances() const {
35193519
return {getTrailingObjects<ProtocolConformanceRef>(),
3520-
Bits.ErasureExpr.NumConformances };
3520+
static_cast<size_t>(Bits.ErasureExpr.NumConformances) };
35213521
}
35223522

35233523
/// Retrieve the conversion expressions mapping requirements from any
@@ -3719,7 +3719,7 @@ class UnresolvedSpecializeExpr final : public Expr,
37193719
/// been bound to archetypes of the entity to be specialized.
37203720
ArrayRef<TypeRepr *> getUnresolvedParams() const {
37213721
return {getTrailingObjects<TypeRepr *>(),
3722-
Bits.UnresolvedSpecializeExpr.NumUnresolvedParams};
3722+
static_cast<size_t>(Bits.UnresolvedSpecializeExpr.NumUnresolvedParams)};
37233723
}
37243724

37253725
SourceLoc getLoc() const { return LAngleLoc; }
@@ -3989,11 +3989,11 @@ class SequenceExpr final : public Expr,
39893989
unsigned getNumElements() const { return Bits.SequenceExpr.NumElements; }
39903990

39913991
MutableArrayRef<Expr*> getElements() {
3992-
return {getTrailingObjects<Expr*>(), Bits.SequenceExpr.NumElements};
3992+
return {getTrailingObjects<Expr*>(), static_cast<size_t>(Bits.SequenceExpr.NumElements)};
39933993
}
39943994

39953995
ArrayRef<Expr*> getElements() const {
3996-
return {getTrailingObjects<Expr*>(), Bits.SequenceExpr.NumElements};
3996+
return {getTrailingObjects<Expr*>(), static_cast<size_t>(Bits.SequenceExpr.NumElements)};
39973997
}
39983998

39993999
Expr *getElement(unsigned i) const {
@@ -4592,7 +4592,7 @@ class CaptureListExpr final : public Expr,
45924592

45934593
ArrayRef<CaptureListEntry> getCaptureList() {
45944594
return {getTrailingObjects<CaptureListEntry>(),
4595-
Bits.CaptureListExpr.NumCaptures};
4595+
static_cast<size_t>(Bits.CaptureListExpr.NumCaptures)};
45964596
}
45974597
AbstractClosureExpr *getClosureBody() { return closureBody; }
45984598
const AbstractClosureExpr *getClosureBody() const { return closureBody; }

include/swift/AST/Stmt.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,12 @@ class BraceStmt final : public Stmt,
212212

213213
/// The elements contained within the BraceStmt.
214214
MutableArrayRef<ASTNode> getElements() {
215-
return {getTrailingObjects<ASTNode>(), Bits.BraceStmt.NumElements};
215+
return {getTrailingObjects<ASTNode>(), static_cast<size_t>(Bits.BraceStmt.NumElements)};
216216
}
217217

218218
/// The elements contained within the BraceStmt (const version).
219219
ArrayRef<ASTNode> getElements() const {
220-
return {getTrailingObjects<ASTNode>(), Bits.BraceStmt.NumElements};
220+
return {getTrailingObjects<ASTNode>(), static_cast<size_t>(Bits.BraceStmt.NumElements)};
221221
}
222222

223223
ASTNode findAsyncNode();
@@ -330,10 +330,10 @@ class YieldStmt final
330330
SourceLoc getEndLoc() const;
331331

332332
ArrayRef<Expr*> getYields() const {
333-
return {getTrailingObjects<Expr*>(), Bits.YieldStmt.NumYields};
333+
return {getTrailingObjects<Expr*>(), static_cast<size_t>(Bits.YieldStmt.NumYields)};
334334
}
335335
MutableArrayRef<Expr*> getMutableYields() {
336-
return {getTrailingObjects<Expr*>(), Bits.YieldStmt.NumYields};
336+
return {getTrailingObjects<Expr*>(), static_cast<size_t>(Bits.YieldStmt.NumYields)};
337337
}
338338

339339
static bool classof(const Stmt *S) { return S->getKind() == StmtKind::Yield; }
@@ -1259,11 +1259,11 @@ class CaseStmt final
12591259
}
12601260

12611261
ArrayRef<CaseLabelItem> getCaseLabelItems() const {
1262-
return {getTrailingObjects<CaseLabelItem>(), Bits.CaseStmt.NumPatterns};
1262+
return {getTrailingObjects<CaseLabelItem>(), static_cast<size_t>(Bits.CaseStmt.NumPatterns)};
12631263
}
12641264

12651265
MutableArrayRef<CaseLabelItem> getMutableCaseLabelItems() {
1266-
return {getTrailingObjects<CaseLabelItem>(), Bits.CaseStmt.NumPatterns};
1266+
return {getTrailingObjects<CaseLabelItem>(), static_cast<size_t>(Bits.CaseStmt.NumPatterns)};
12671267
}
12681268

12691269
unsigned getNumCaseLabelItems() const { return Bits.CaseStmt.NumPatterns; }
@@ -1448,7 +1448,7 @@ class SwitchStmt final : public LabeledStmt,
14481448
void setSubjectExpr(Expr *e) { SubjectExpr = e; }
14491449

14501450
ArrayRef<ASTNode> getRawCases() const {
1451-
return {getTrailingObjects<ASTNode>(), Bits.SwitchStmt.CaseCount};
1451+
return {getTrailingObjects<ASTNode>(), static_cast<size_t>(Bits.SwitchStmt.CaseCount)};
14521452
}
14531453

14541454
private:
@@ -1541,10 +1541,10 @@ class DoCatchStmt final
15411541
void setBody(Stmt *s) { Body = s; }
15421542

15431543
ArrayRef<CaseStmt *> getCatches() const {
1544-
return {getTrailingObjects<CaseStmt *>(), Bits.DoCatchStmt.NumCatches};
1544+
return {getTrailingObjects<CaseStmt *>(), static_cast<size_t>(Bits.DoCatchStmt.NumCatches)};
15451545
}
15461546
MutableArrayRef<CaseStmt *> getMutableCatches() {
1547-
return {getTrailingObjects<CaseStmt *>(), Bits.DoCatchStmt.NumCatches};
1547+
return {getTrailingObjects<CaseStmt *>(), static_cast<size_t>(Bits.DoCatchStmt.NumCatches)};
15481548
}
15491549

15501550
/// Retrieve the complete set of branches for this do-catch statement.

include/swift/AST/TypeRepr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ class TupleTypeRepr final : public TypeRepr,
917917

918918
ArrayRef<TupleTypeReprElement> getElements() const {
919919
return { getTrailingObjects<TupleTypeReprElement>(),
920-
Bits.TupleTypeRepr.NumElements };
920+
static_cast<size_t>(Bits.TupleTypeRepr.NumElements) };
921921
}
922922

923923
void getElementTypes(SmallVectorImpl<TypeRepr *> &Types) const {
@@ -1003,7 +1003,7 @@ class CompositionTypeRepr final : public TypeRepr,
10031003

10041004
public:
10051005
ArrayRef<TypeRepr *> getTypes() const {
1006-
return {getTrailingObjects<TypeRepr*>(), Bits.CompositionTypeRepr.NumTypes};
1006+
return {getTrailingObjects<TypeRepr*>(), static_cast<size_t>(Bits.CompositionTypeRepr.NumTypes)};
10071007
}
10081008
SourceLoc getSourceLoc() const { return FirstTypeLoc; }
10091009
SourceRange getCompositionRange() const { return CompositionRange; }
@@ -1494,7 +1494,7 @@ class SILBoxTypeRepr final : public TypeRepr,
14941494

14951495
ArrayRef<Field> getFields() const {
14961496
return {getTrailingObjects<Field>(),
1497-
Bits.SILBoxTypeRepr.NumFields};
1497+
static_cast<size_t>(Bits.SILBoxTypeRepr.NumFields)};
14981498
}
14991499
ArrayRef<TypeRepr *> getGenericArguments() const {
15001500
return {getTrailingObjects<TypeRepr*>(),

include/swift/AST/Types.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,7 +2824,7 @@ class BoundGenericType : public NominalOrBoundGenericNominalType,
28242824

28252825
/// Retrieve the set of generic arguments provided at this level.
28262826
ArrayRef<Type> getGenericArgs() const {
2827-
return {getTrailingObjectsPointer(), Bits.BoundGenericType.GenericArgCount};
2827+
return {getTrailingObjectsPointer(), static_cast<size_t>(Bits.BoundGenericType.GenericArgCount)};
28282828
}
28292829

28302830
SmallVector<Type, 2> getExpandedGenericArgs();
@@ -6365,7 +6365,7 @@ class ProtocolCompositionType final : public TypeBase,
63656365
/// a protocol composition type; you also have to look at
63666366
/// hasExplicitAnyObject().
63676367
ArrayRef<Type> getMembers() const {
6368-
return {getTrailingObjects<Type>(), Bits.ProtocolCompositionType.Count};
6368+
return {getTrailingObjects<Type>(), static_cast<size_t>(Bits.ProtocolCompositionType.Count)};
63696369
}
63706370

63716371
InvertibleProtocolSet getInverses() const { return Inverses; }
@@ -6463,7 +6463,7 @@ class ParameterizedProtocolType final : public TypeBase,
64636463

64646464
ArrayRef<Type> getArgs() const {
64656465
return {getTrailingObjects<Type>(),
6466-
Bits.ParameterizedProtocolType.ArgCount};
6466+
static_cast<size_t>(Bits.ParameterizedProtocolType.ArgCount)};
64676467
}
64686468

64696469
bool requiresClass() const {
@@ -7513,7 +7513,7 @@ class ErrorUnionType final
75137513
static Type get(const ASTContext &ctx, ArrayRef<Type> terms);
75147514

75157515
ArrayRef<Type> getTerms() const {
7516-
return { getTrailingObjects<Type>(), Bits.ErrorUnionType.NumTerms };
7516+
return { getTrailingObjects<Type>(), static_cast<size_t>(Bits.ErrorUnionType.NumTerms) };
75177517
};
75187518

75197519
// Support for FoldingSet.

lib/AST/Stmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ CaseStmt::CaseStmt(CaseParentKind parentKind, SourceLoc itemIntroducerLoc,
771771
}
772772

773773
MutableArrayRef<CaseLabelItem> items{getTrailingObjects<CaseLabelItem>(),
774-
Bits.CaseStmt.NumPatterns};
774+
static_cast<size_t>(Bits.CaseStmt.NumPatterns)};
775775

776776
// At the beginning mark all of our var decls as being owned by this
777777
// statement. In the typechecker we wireup the case stmt var decl list since

0 commit comments

Comments
 (0)