Skip to content

Commit d6be820

Browse files
authored
Merge pull request #64449 from atrick/cleanup-conversion-tests
[NFC] Cleanup implicit pointer conversion diagnostic tests
2 parents 2f8c1a4 + 3dc832b commit d6be820

File tree

2 files changed

+26
-27
lines changed

2 files changed

+26
-27
lines changed

test/SILGen/diagnose_implicit_raw_conversion.swift

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ func test_errors<T>(arg: T, sarg: String) {
3838

3939
let constArray: [T] = [arg]
4040
readBytes(constArray) // expected-warning {{forming 'UnsafeRawPointer' to a variable of type '[T]'; this is likely incorrect because 'T' may contain an object reference.}}
41+
read_char(constArray) // expected-warning {{forming 'UnsafePointer<CChar>' (aka 'UnsafePointer<Int8>') to a variable of type '[T]'; this is likely incorrect because 'T' may contain an object reference.}}
42+
read_uchar(constArray) // expected-warning {{forming 'UnsafePointer<UInt8>' to a variable of type '[T]'; this is likely incorrect because 'T' may contain an object reference.}}
4143

4244
var array: [T] = [arg]
4345
readBytes(&array) // expected-warning {{forming 'UnsafeRawPointer' to a variable of type '[T]'; this is likely incorrect because 'T' may contain an object reference.}}
@@ -81,6 +83,8 @@ func test_explicit<T>(arg: T, sarg: String) {
8183
let constArray: [T] = [arg]
8284
constArray.withUnsafeBytes() {
8385
readBytes($0.baseAddress!)
86+
read_char($0.baseAddress!)
87+
read_uchar($0.baseAddress!)
8488
}
8589
var array: [T] = [arg]
8690
array.withUnsafeBytes() {
@@ -118,10 +122,10 @@ func test_accepted<I: FixedWidthInteger>(intArg: I, sarg: String, simdArg: SIMD4
118122
read_uchar(&int)
119123
write_uchar(&int)
120124

121-
let constArray: [I] = [intArg]
122-
readBytes(constArray)
123-
// read_char(constArray) - this case never worked because of a bug in SE-0324
124-
// read_uchar(constArray) - this case never worked because of a bug in SE-0324
125+
let constIntArray: [I] = [intArg]
126+
readBytes(constIntArray)
127+
read_char(constIntArray)
128+
read_uchar(constIntArray)
125129

126130
var intArray: [I] = [intArg]
127131
readBytes(&intArray)
@@ -131,6 +135,11 @@ func test_accepted<I: FixedWidthInteger>(intArg: I, sarg: String, simdArg: SIMD4
131135
read_uchar(&intArray)
132136
write_uchar(&intArray)
133137

138+
let constByteArray: [UInt8] = [0]
139+
readBytes(constByteArray)
140+
read_char(constByteArray)
141+
read_uchar(constByteArray)
142+
134143
var byteArray: [UInt8] = [0]
135144
readBytes(&byteArray)
136145
writeBytes(&byteArray)
@@ -140,6 +149,19 @@ func test_accepted<I: FixedWidthInteger>(intArg: I, sarg: String, simdArg: SIMD4
140149
read_uchar(byteArray)
141150
write_uchar(&byteArray)
142151

152+
let constInt8Array: [Int8] = [0]
153+
readBytes(constInt8Array)
154+
read_char(constInt8Array)
155+
read_uchar(constInt8Array)
156+
157+
var int8Array: [Int8] = [0]
158+
readBytes(&int8Array)
159+
writeBytes(&int8Array)
160+
read_char(&int8Array)
161+
write_char(&int8Array)
162+
read_uchar(&int8Array)
163+
write_uchar(&int8Array)
164+
143165
let string: String = sarg
144166
readBytes(string)
145167
readUInt8(string)

test/SILGen/diagnose_implicit_raw_conversion_unsupported.swift

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,3 @@ func test_unsupported<T>(arg: T) {
3939
writeInt8(&byteArray) // expected-error {{cannot convert value of type 'UnsafeMutablePointer<UInt8>' to expected argument type 'UnsafeMutablePointer<Int8>'}}
4040
// expected-note@-1 {{arguments to generic parameter 'Pointee' ('UInt8' and 'Int8') are expected to be equal}}
4141
}
42-
43-
// Array<T> to C pointer conversion is supported under SE-0324
44-
func test_array_to_c_pointer_concrete() {
45-
let constIntArray: [Int8] = [0]
46-
read_uchar(constIntArray)
47-
48-
let constUIntArray: [UInt8] = [0]
49-
read_char(constUIntArray)
50-
51-
var intArray: [Int8] = [0] // expected-warning {{variable 'intArray' was never mutated; consider changing to 'let' constant}}
52-
read_uchar(intArray)
53-
54-
var uintArray: [UInt8] = [0] // expected-warning {{variable 'uintArray' was never mutated; consider changing to 'let' constant}}
55-
read_char(uintArray)
56-
57-
}
58-
59-
// Array<T> to C pointer conversion is supported under SE-0324
60-
func test_array_to_c_pointer_generic<T>(arg: T) {
61-
let constArray: [T] = [arg]
62-
read_char(constArray)
63-
read_uchar(constArray)
64-
}

0 commit comments

Comments
 (0)