Skip to content

Commit e467a70

Browse files
lorenteyMax Moiseev
authored andcommitted
[stdlib] Fix sign extension in word -> multi-word integer conversions
This fixes integer conversion issues on 32-bit platforms. (cherry picked from commit 735fe97)
1 parent 14984ee commit e467a70

File tree

2 files changed

+1
-18
lines changed

2 files changed

+1
-18
lines changed

stdlib/public/core/Integers.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2260,7 +2260,7 @@ ${unsafeOperationComment(x.operator)}
22602260

22612261
@inline(__always)
22622262
public init<T : BinaryInteger>(extendingOrTruncating source: T) {
2263-
if Self.bitWidth <= ${word_bits} || source.bitWidth <= ${word_bits} {
2263+
if Self.bitWidth <= ${word_bits} {
22642264
self = Self.init(_truncatingBits: source._lowWord)
22652265
}
22662266
else {

test/stdlib/Integers.swift.gyb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -622,21 +622,4 @@ tests.test("signum/concrete") {
622622
}
623623

624624

625-
dwTests.test("Words") {
626-
expectEqualSequence((0 as DoubleWidth<Int8>).words, [0])
627-
expectEqualSequence((1 as DoubleWidth<Int8>).words, [1])
628-
expectEqualSequence((-1 as DoubleWidth<Int8>).words, [UInt.max])
629-
expectEqualSequence((256 as DoubleWidth<Int8>).words, [256])
630-
expectEqualSequence((-256 as DoubleWidth<Int8>).words, [UInt.max - 255])
631-
expectEqualSequence(DoubleWidth<Int8>.max.words, [32767])
632-
expectEqualSequence(DoubleWidth<Int8>.min.words, [UInt.max - 32767])
633-
634-
expectEqualSequence((0 as Int1024).words,
635-
repeatElement(0 as UInt, count: 1024 / UInt.bitWidth))
636-
expectEqualSequence((-1 as Int1024).words,
637-
repeatElement(UInt.max, count: 1024 / UInt.bitWidth))
638-
expectEqualSequence((1 as Int1024).words,
639-
[1] + Array(repeating: 0, count: 1024 / UInt.bitWidth - 1))
640-
}
641-
642625
runAllTests()

0 commit comments

Comments
 (0)