Skip to content

Commit db7d1e7

Browse files
authored
Merge pull request #60309 from glessard/rdar97029576-minimal-stdlib
[test] modify to be compatible with minimal stdlib
2 parents d214398 + 57bee9c commit db7d1e7

File tree

1 file changed

+40
-21
lines changed

1 file changed

+40
-21
lines changed

validation-test/stdlib/UnsafeRawPointerInternal.swift

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,60 @@
22
// RUN: %target-codesign %t.out
33
// RUN: %target-run %t.out
44
// REQUIRES: executable_test
5-
// UNSUPPORTED: freestanding
65

76
import Swift
87
import StdlibUnittest
98

10-
var UnsafeRawPointerTestSuite =
11-
TestSuite("UnsafeRawPointerTestSuite")
9+
var UnsafeRawPointerTestSuite = TestSuite("UnsafeRawPointerTestSuite")
1210

13-
UnsafeRawPointerTestSuite.test("load.unaligned.SIMD")
11+
UnsafeRawPointerTestSuite.test("load.unaligned.largeAlignment")
1412
.skip(.custom({
15-
if #available(SwiftStdlib 5.7, *) { return false }
16-
return true
17-
}, reason: "Requires Swift 5.7's stdlib"))
13+
if #available(SwiftStdlib 5.7, *) { return false } else { return true }
14+
}, reason: "Requires standard library from Swift 5.7"))
1815
.code {
1916
guard #available(SwiftStdlib 5.7, *) else { return }
20-
var bytes: [UInt8] = Array(0..<64)
2117
var offset = 3
22-
let vector16 = bytes.withUnsafeBytes { buffer -> SIMD16<UInt8> in
23-
let aligned = buffer.baseAddress!.alignedUp(for: SIMD16<UInt8>.self)
18+
let int128 = withUnsafeTemporaryAllocation(of: UInt8.self, capacity: 64) {
19+
temporary -> Builtin.Int128 in
20+
let buffer = UnsafeRawBufferPointer(temporary)
21+
_ = temporary.initialize(from: repeatElement(0, count: 64))
22+
// Load a 128-bit floating point value
23+
let fp = buffer.loadUnaligned(fromByteOffset: offset, as: Builtin.FPIEEE128.self)
24+
noop(fp)
25+
temporary.baseAddress!.deinitialize(count: 64)
26+
_ = temporary.initialize(from: 0..<64)
27+
let aligned = buffer.baseAddress!.alignedUp(for: Builtin.Int128.self)
2428
offset += buffer.baseAddress!.distance(to: aligned)
25-
return buffer.loadUnaligned(fromByteOffset: offset, as: SIMD16<UInt8>.self)
29+
// Load and return a 128-bit integer value
30+
return buffer.loadUnaligned(fromByteOffset: offset, as: Builtin.Int128.self)
2631
}
27-
expectEqual(Int(vector16[0]), offset)
28-
var lastIndex = vector16.indices.last!
29-
expectEqual(Int(vector16[lastIndex]), offset+lastIndex)
32+
withUnsafeBytes(of: int128) {
33+
expectEqual(Int($0[0]), offset)
34+
let lastIndex = $0.indices.last!
35+
expectEqual(Int($0[lastIndex]), offset+lastIndex)
36+
}
37+
}
3038

31-
offset = 11
32-
let vector32 = bytes.withUnsafeMutableBytes { buffer -> SIMD32<UInt8> in
33-
let aligned = buffer.baseAddress!.alignedUp(for: SIMD32<UInt8>.self)
39+
UnsafeRawPointerTestSuite.test("load.unaligned.largeAlignment.mutablePointer")
40+
.skip(.custom({
41+
if #available(SwiftStdlib 5.7, *) { return false } else { return true }
42+
}, reason: "Requires standard library from Swift 5.7"))
43+
.code {
44+
guard #available(SwiftStdlib 5.7, *) else { return }
45+
var offset = 11
46+
let int128 = withUnsafeTemporaryAllocation(of: UInt8.self, capacity: 64) {
47+
temporary -> Builtin.Int128 in
48+
let buffer = UnsafeMutableRawBufferPointer(temporary)
49+
buffer.copyBytes(from: 0..<64)
50+
let aligned = buffer.baseAddress!.alignedUp(for: Builtin.Int128.self)
3451
offset += buffer.baseAddress!.distance(to: aligned)
35-
return buffer.loadUnaligned(fromByteOffset: offset, as: SIMD32<UInt8>.self)
52+
return buffer.loadUnaligned(fromByteOffset: offset, as: Builtin.Int128.self)
53+
}
54+
withUnsafeBytes(of: int128) {
55+
expectEqual(Int($0[0]), offset)
56+
let lastIndex = $0.indices.last!
57+
expectEqual(Int($0[lastIndex]), offset+lastIndex)
3658
}
37-
expectEqual(Int(vector32[0]), offset)
38-
lastIndex = vector32.indices.last!
39-
expectEqual(Int(vector32[lastIndex]), offset+lastIndex)
4059
}
4160

4261
runAllTests()

0 commit comments

Comments
 (0)