Skip to content

Commit a354f26

Browse files
committed
Fix unit tests that relied on nontrivial to raw conversion.
1 parent 64e1ce2 commit a354f26

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

test/SILGen/pointer_conversion.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func takesMutableRawPointer(_ x: UnsafeMutableRawPointer) {}
2020
func takesConstRawPointer(_ x: UnsafeRawPointer) {}
2121
func takesOptConstRawPointer(_ x: UnsafeRawPointer?, and: Int) {}
2222
func takesOptOptConstRawPointer(_ x: UnsafeRawPointer??, and: Int) {}
23+
func takesMutableFunctionPointer(_ x: UnsafeMutablePointer<() -> Void>) {}
2324

2425
// CHECK-LABEL: sil hidden [ossa] @$s18pointer_conversion0A9ToPointeryySpySiG_SPySiGSvtF
2526
// CHECK: bb0([[MP:%.*]] : $UnsafeMutablePointer<Int>, [[CP:%.*]] : $UnsafePointer<Int>, [[MRP:%.*]] : $UnsafeMutableRawPointer):
@@ -278,7 +279,7 @@ func functionInoutToPointer() {
278279

279280
// CHECK: [[REABSTRACT_BUF:%.*]] = alloc_stack $@callee_guaranteed @substituted <τ_0_0> () -> @out τ_0_0 for <()>
280281
// CHECK: address_to_pointer [stack_protection] [[REABSTRACT_BUF]]
281-
takesMutableVoidPointer(&f)
282+
takesMutableFunctionPointer(&f)
282283
}
283284

284285
// rdar://problem/31781386

validation-test/stdlib/UnicodeUTFEncoders.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,17 @@ func nsEncode<CodeUnit>(
8484
length: 4,
8585
encoding: String.Encoding.utf32LittleEndian.rawValue)!
8686

87-
s.getBytes(
88-
&buffer,
89-
maxLength: buffer.count,
90-
usedLength: &used,
91-
encoding: encoding.rawValue,
92-
options: [],
93-
range: NSRange(location: 0, length: s.length),
94-
remaining: nil)
87+
let count = buffer.count
88+
_ = buffer.withUnsafeMutableBytes { bufferBytes in
89+
s.getBytes(
90+
bufferBytes.baseAddress,
91+
maxLength: count,
92+
usedLength: &used,
93+
encoding: encoding.rawValue,
94+
options: [],
95+
range: NSRange(location: 0, length: s.length),
96+
remaining: nil)
97+
}
9598
}
9699

97100
final class CodecTest<Codec : TestableUnicodeCodec> {

0 commit comments

Comments
 (0)