Skip to content

Commit a3b60ed

Browse files
committed
SIL: avoid truncation warnings on Windows (NFCI)
`enum` is a signed integer type on some platforms. The return value of `std::numeric_limits<T>::max()` is a `size_t` which is unsigned. Further manipulation retains the unsigned-ness until the assignment which results in truncation. Change the type to a `constexpr` constant definition and remove the `enum` type along with a type conversion to an explicitly unsigned integral type.
1 parent 159259a commit a3b60ed

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

include/swift/SIL/SILBasicBlock.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ public SwiftObjectHeader {
153153
~SILBasicBlock();
154154

155155
enum { numCustomBits = std::numeric_limits<CustomBitsType>::digits };
156-
enum { maxBitfieldID = std::numeric_limits<uint64_t>::max() };
156+
157+
constexpr static const size_t maxBitfieldID =
158+
std::numeric_limits<uint64_t>::max();
157159

158160
/// Gets the ID (= index in the function's block list) of the block.
159161
///

include/swift/SIL/SILNode.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ class alignas(8) SILNode :
127127
enum { NumMarkDependenceKindBits = 2 };
128128

129129
enum { numCustomBits = 20 };
130-
enum { maxBitfieldID = std::numeric_limits<uint64_t>::max() >> numCustomBits };
130+
131+
constexpr static const size_t maxBitfieldID =
132+
std::numeric_limits<uint64_t>::max() >> numCustomBits;
131133

132134
protected:
133135
friend class SILInstruction;

include/swift/SIL/SILValue.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,9 @@ ValueOwnershipKind::getForwardingOperandOwnership(bool allowUnowned) const {
10211021
class Operand {
10221022
public:
10231023
enum { numCustomBits = 8 };
1024-
enum { maxBitfieldID = std::numeric_limits<uint64_t>::max() >> numCustomBits };
1024+
1025+
constexpr static const size_t maxBitfieldID =
1026+
std::numeric_limits<uint64_t>::max() >> numCustomBits;
10251027

10261028
private:
10271029
template <class, class> friend class SILBitfield;

0 commit comments

Comments
 (0)