Skip to content

Commit 073905b

Browse files
committed
[32-bit Linux] Handle size_t/uint64_t assumptions
There’s a few places where size_t is used for a field/parameter when constructing an array for types. Unfortunately, the Bitfields that were backing the inputs to these at some point after 4.1 grew past 32 bits and are now backed by a uint64_t. Even though the slice of the bitfield is small enough for 32-bit, clang sees these slices as 64-bit and complains if there isn’t a cast involved.
1 parent 63b61dd commit 073905b

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,7 @@ class ImportDecl final : public Decl,
15991599

16001600
ArrayRef<AccessPathElement> getFullAccessPath() const {
16011601
return {getTrailingObjects<AccessPathElement>(),
1602-
Bits.ImportDecl.NumPathElements};
1602+
static_cast<size_t>(Bits.ImportDecl.NumPathElements)};
16031603
}
16041604

16051605
ArrayRef<AccessPathElement> getModulePath() const {

include/swift/AST/Expr.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,10 +2114,10 @@ class CollectionExpr : public Expr {
21142114
/// that trailing commas are currently allowed, and that invalid code may have
21152115
/// stray or missing commas.
21162116
MutableArrayRef<SourceLoc> getCommaLocs() {
2117-
return {getTrailingSourceLocs(), Bits.CollectionExpr.NumCommas};
2117+
return {getTrailingSourceLocs(), static_cast<size_t>(Bits.CollectionExpr.NumCommas)};
21182118
}
21192119
ArrayRef<SourceLoc> getCommaLocs() const {
2120-
return {getTrailingSourceLocs(), Bits.CollectionExpr.NumCommas};
2120+
return {getTrailingSourceLocs(), static_cast<size_t>(Bits.CollectionExpr.NumCommas)};
21212121
}
21222122
unsigned getNumCommas() const { return Bits.CollectionExpr.NumCommas; }
21232123

@@ -2911,7 +2911,7 @@ class TupleShuffleExpr final : public ImplicitConversionExpr,
29112911

29122912
ArrayRef<int> getElementMapping() const {
29132913
return {getTrailingObjects<int>(),
2914-
Bits.TupleShuffleExpr.NumElementMappings};
2914+
static_cast<size_t>(Bits.TupleShuffleExpr.NumElementMappings)};
29152915
}
29162916

29172917
/// What is the type impact of this shuffle?
@@ -2938,7 +2938,7 @@ class TupleShuffleExpr final : public ImplicitConversionExpr,
29382938
/// Retrieve the argument indices for the variadic arguments.
29392939
ArrayRef<unsigned> getVariadicArgs() const {
29402940
return {getTrailingObjects<unsigned>(),
2941-
Bits.TupleShuffleExpr.NumVariadicArgs};
2941+
static_cast<size_t>(Bits.TupleShuffleExpr.NumVariadicArgs)};
29422942
}
29432943

29442944
/// Retrieve the owner of the default arguments.
@@ -2947,13 +2947,13 @@ class TupleShuffleExpr final : public ImplicitConversionExpr,
29472947
/// Retrieve the caller-defaulted arguments.
29482948
ArrayRef<Expr *> getCallerDefaultArgs() const {
29492949
return {getTrailingObjects<Expr*>(),
2950-
Bits.TupleShuffleExpr.NumCallerDefaultArgs};
2950+
static_cast<size_t>(Bits.TupleShuffleExpr.NumCallerDefaultArgs)};
29512951
}
29522952

29532953
/// Retrieve the caller-defaulted arguments.
29542954
MutableArrayRef<Expr *> getCallerDefaultArgs() {
29552955
return {getTrailingObjects<Expr*>(),
2956-
Bits.TupleShuffleExpr.NumCallerDefaultArgs};
2956+
static_cast<size_t>(Bits.TupleShuffleExpr.NumCallerDefaultArgs)};
29572957
}
29582958

29592959
static bool classof(const Expr *E) {

include/swift/AST/TypeRepr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1079,7 +1079,7 @@ class SILBoxTypeRepr final : public TypeRepr,
10791079
}
10801080
ArrayRef<TypeRepr *> getGenericArguments() const {
10811081
return {getTrailingObjects<TypeRepr*>(),
1082-
Bits.SILBoxTypeRepr.NumGenericArgs};
1082+
static_cast<size_t>(Bits.SILBoxTypeRepr.NumGenericArgs)};
10831083
}
10841084

10851085
GenericParamList *getGenericParams() const {

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4650,7 +4650,7 @@ class ArchetypeType final : public SubstitutableType,
46504650
/// type shall conform.
46514651
ArrayRef<ProtocolDecl *> getConformsTo() const {
46524652
return { getTrailingObjects<ProtocolDecl *>(),
4653-
Bits.ArchetypeType.NumProtocols };
4653+
static_cast<size_t>(Bits.ArchetypeType.NumProtocols) };
46544654
}
46554655

46564656
/// requiresClass - True if the type can only be substituted with class types.

include/swift/SIL/SILInstruction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,12 +1360,12 @@ class AllocStackInst final
13601360

13611361
ArrayRef<Operand> getAllOperands() const {
13621362
return { getTrailingObjects<Operand>(),
1363-
SILInstruction::Bits.AllocStackInst.NumOperands };
1363+
static_cast<size_t>(SILInstruction::Bits.AllocStackInst.NumOperands) };
13641364
}
13651365

13661366
MutableArrayRef<Operand> getAllOperands() {
13671367
return { getTrailingObjects<Operand>(),
1368-
SILInstruction::Bits.AllocStackInst.NumOperands };
1368+
static_cast<size_t>(SILInstruction::Bits.AllocStackInst.NumOperands) };
13691369
}
13701370

13711371
ArrayRef<Operand> getTypeDependentOperands() const {

0 commit comments

Comments
 (0)