Skip to content

[AST] Explicitly cast uint64_t to size_t for 32-bit platforms #79340

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
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
2 changes: 1 addition & 1 deletion include/swift/AST/Attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2962,7 +2962,7 @@ class AllowFeatureSuppressionAttr final

ArrayRef<Identifier> getSuppressedFeatures() const {
return {getTrailingObjects<Identifier>(),
Bits.AllowFeatureSuppressionAttr.NumFeatures};
static_cast<size_t>(Bits.AllowFeatureSuppressionAttr.NumFeatures)};
}

static bool classof(const DeclAttribute *DA) {
Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8672,7 +8672,7 @@ class EnumCaseDecl final : public Decl,
/// Get the list of elements declared in this case.
ArrayRef<EnumElementDecl *> getElements() const {
return {getTrailingObjects<EnumElementDecl *>(),
Bits.EnumCaseDecl.NumElements};
static_cast<size_t>(Bits.EnumCaseDecl.NumElements)};
}
SourceRange getSourceRange() const;

Expand Down
14 changes: 7 additions & 7 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2453,10 +2453,10 @@ class CollectionExpr : public Expr {

/// Retrieve the elements stored in the collection.
ArrayRef<Expr *> getElements() const {
return {getTrailingObjectsPointer(), Bits.CollectionExpr.NumSubExprs};
return {getTrailingObjectsPointer(), static_cast<size_t>(Bits.CollectionExpr.NumSubExprs)};
}
MutableArrayRef<Expr *> getElements() {
return {getTrailingObjectsPointer(), Bits.CollectionExpr.NumSubExprs};
return {getTrailingObjectsPointer(), static_cast<size_t>(Bits.CollectionExpr.NumSubExprs)};
}
Expr *getElement(unsigned i) const { return getElements()[i]; }
void setElement(unsigned i, Expr *E) { getElements()[i] = E; }
Expand Down Expand Up @@ -3517,7 +3517,7 @@ class ErasureExpr final : public ImplicitConversionExpr,
/// that corresponding protocol).
ArrayRef<ProtocolConformanceRef> getConformances() const {
return {getTrailingObjects<ProtocolConformanceRef>(),
Bits.ErasureExpr.NumConformances };
static_cast<size_t>(Bits.ErasureExpr.NumConformances) };
}

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

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

MutableArrayRef<Expr*> getElements() {
return {getTrailingObjects<Expr*>(), Bits.SequenceExpr.NumElements};
return {getTrailingObjects<Expr*>(), static_cast<size_t>(Bits.SequenceExpr.NumElements)};
}

ArrayRef<Expr*> getElements() const {
return {getTrailingObjects<Expr*>(), Bits.SequenceExpr.NumElements};
return {getTrailingObjects<Expr*>(), static_cast<size_t>(Bits.SequenceExpr.NumElements)};
}

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

ArrayRef<CaptureListEntry> getCaptureList() {
return {getTrailingObjects<CaptureListEntry>(),
Bits.CaptureListExpr.NumCaptures};
static_cast<size_t>(Bits.CaptureListExpr.NumCaptures)};
}
AbstractClosureExpr *getClosureBody() { return closureBody; }
const AbstractClosureExpr *getClosureBody() const { return closureBody; }
Expand Down
18 changes: 9 additions & 9 deletions include/swift/AST/Stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ class BraceStmt final : public Stmt,

/// The elements contained within the BraceStmt.
MutableArrayRef<ASTNode> getElements() {
return {getTrailingObjects<ASTNode>(), Bits.BraceStmt.NumElements};
return {getTrailingObjects<ASTNode>(), static_cast<size_t>(Bits.BraceStmt.NumElements)};
}

/// The elements contained within the BraceStmt (const version).
ArrayRef<ASTNode> getElements() const {
return {getTrailingObjects<ASTNode>(), Bits.BraceStmt.NumElements};
return {getTrailingObjects<ASTNode>(), static_cast<size_t>(Bits.BraceStmt.NumElements)};
}

ASTNode findAsyncNode();
Expand Down Expand Up @@ -330,10 +330,10 @@ class YieldStmt final
SourceLoc getEndLoc() const;

ArrayRef<Expr*> getYields() const {
return {getTrailingObjects<Expr*>(), Bits.YieldStmt.NumYields};
return {getTrailingObjects<Expr*>(), static_cast<size_t>(Bits.YieldStmt.NumYields)};
}
MutableArrayRef<Expr*> getMutableYields() {
return {getTrailingObjects<Expr*>(), Bits.YieldStmt.NumYields};
return {getTrailingObjects<Expr*>(), static_cast<size_t>(Bits.YieldStmt.NumYields)};
}

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

ArrayRef<CaseLabelItem> getCaseLabelItems() const {
return {getTrailingObjects<CaseLabelItem>(), Bits.CaseStmt.NumPatterns};
return {getTrailingObjects<CaseLabelItem>(), static_cast<size_t>(Bits.CaseStmt.NumPatterns)};
}

MutableArrayRef<CaseLabelItem> getMutableCaseLabelItems() {
return {getTrailingObjects<CaseLabelItem>(), Bits.CaseStmt.NumPatterns};
return {getTrailingObjects<CaseLabelItem>(), static_cast<size_t>(Bits.CaseStmt.NumPatterns)};
}

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

ArrayRef<ASTNode> getRawCases() const {
return {getTrailingObjects<ASTNode>(), Bits.SwitchStmt.CaseCount};
return {getTrailingObjects<ASTNode>(), static_cast<size_t>(Bits.SwitchStmt.CaseCount)};
}

private:
Expand Down Expand Up @@ -1541,10 +1541,10 @@ class DoCatchStmt final
void setBody(Stmt *s) { Body = s; }

ArrayRef<CaseStmt *> getCatches() const {
return {getTrailingObjects<CaseStmt *>(), Bits.DoCatchStmt.NumCatches};
return {getTrailingObjects<CaseStmt *>(), static_cast<size_t>(Bits.DoCatchStmt.NumCatches)};
}
MutableArrayRef<CaseStmt *> getMutableCatches() {
return {getTrailingObjects<CaseStmt *>(), Bits.DoCatchStmt.NumCatches};
return {getTrailingObjects<CaseStmt *>(), static_cast<size_t>(Bits.DoCatchStmt.NumCatches)};
}

/// Retrieve the complete set of branches for this do-catch statement.
Expand Down
6 changes: 3 additions & 3 deletions include/swift/AST/TypeRepr.h
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ class TupleTypeRepr final : public TypeRepr,

ArrayRef<TupleTypeReprElement> getElements() const {
return { getTrailingObjects<TupleTypeReprElement>(),
Bits.TupleTypeRepr.NumElements };
static_cast<size_t>(Bits.TupleTypeRepr.NumElements) };
}

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

public:
ArrayRef<TypeRepr *> getTypes() const {
return {getTrailingObjects<TypeRepr*>(), Bits.CompositionTypeRepr.NumTypes};
return {getTrailingObjects<TypeRepr*>(), static_cast<size_t>(Bits.CompositionTypeRepr.NumTypes)};
}
SourceLoc getSourceLoc() const { return FirstTypeLoc; }
SourceRange getCompositionRange() const { return CompositionRange; }
Expand Down Expand Up @@ -1494,7 +1494,7 @@ class SILBoxTypeRepr final : public TypeRepr,

ArrayRef<Field> getFields() const {
return {getTrailingObjects<Field>(),
Bits.SILBoxTypeRepr.NumFields};
static_cast<size_t>(Bits.SILBoxTypeRepr.NumFields)};
}
ArrayRef<TypeRepr *> getGenericArguments() const {
return {getTrailingObjects<TypeRepr*>(),
Expand Down
8 changes: 4 additions & 4 deletions include/swift/AST/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2824,7 +2824,7 @@ class BoundGenericType : public NominalOrBoundGenericNominalType,

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

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

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

ArrayRef<Type> getArgs() const {
return {getTrailingObjects<Type>(),
Bits.ParameterizedProtocolType.ArgCount};
static_cast<size_t>(Bits.ParameterizedProtocolType.ArgCount)};
}

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

ArrayRef<Type> getTerms() const {
return { getTrailingObjects<Type>(), Bits.ErrorUnionType.NumTerms };
return { getTrailingObjects<Type>(), static_cast<size_t>(Bits.ErrorUnionType.NumTerms) };
};

// Support for FoldingSet.
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/Stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ CaseStmt::CaseStmt(CaseParentKind parentKind, SourceLoc itemIntroducerLoc,
}

MutableArrayRef<CaseLabelItem> items{getTrailingObjects<CaseLabelItem>(),
Bits.CaseStmt.NumPatterns};
static_cast<size_t>(Bits.CaseStmt.NumPatterns)};

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