@@ -41,37 +41,73 @@ func test_mutable_raw_pointer(ptr: UnsafeMutableRawPointer) {
41
41
%for TestPtrSize in ['16', '32', '64']:
42
42
// Immutable pointers can be converted only to their immutable (regardless of sign) counterparts.
43
43
func test_${TestPtrSize}_bit_ptrs(sptr: UnsafePointer<Int${TestPtrSize}>,
44
- uptr: UnsafePointer<UInt${TestPtrSize}>) {
45
- char_ptr_func(sptr) // expected-error {{}}
46
- char_ptr_func(uptr) // expected-error {{}}
44
+ uptr: UnsafePointer<UInt${TestPtrSize}>,
45
+ osptr: UnsafePointer<Int${TestPtrSize}>?,
46
+ ouptr: UnsafePointer<UInt${TestPtrSize}>?) {
47
+ % for pointer in ['sptr', 'uptr']:
48
+ char_ptr_func(${pointer}) // expected-error {{}}
49
+ opt_char_ptr_func(${pointer}) // expected-error {{}}
47
50
48
- const_char_ptr_func(sptr ) // Ok
49
- const_char_ptr_func(uptr ) // Ok
51
+ const_char_ptr_func(${pointer} ) // Ok
52
+ const_opt_char_ptr_func(${pointer} ) // Ok
50
53
51
- unsigned_char_ptr_func(sptr ) // expected-error {{}}
52
- unsigned_char_ptr_func(uptr ) // expected-error {{}}
54
+ unsigned_char_ptr_func(${pointer} ) // expected-error {{}}
55
+ unsigned_opt_char_ptr_func(${pointer} ) // expected-error {{}}
53
56
54
- const_unsigned_char_ptr_func(sptr) // Ok
55
- const_unsigned_char_ptr_func(uptr) // Ok
57
+ const_unsigned_char_ptr_func(${pointer}) // Ok
58
+ const_opt_unsigned_char_ptr_func(${pointer}) // Ok
59
+ % end
60
+
61
+ % for pointer in ['osptr', 'ouptr']:
62
+ opt_char_ptr_func(${pointer}) // expected-error {{}}
63
+ const_opt_char_ptr_func(${pointer}) // Ok
64
+ unsigned_opt_char_ptr_func(${pointer}) // expected-error {{}}
65
+ const_opt_unsigned_char_ptr_func(${pointer}) // Ok
66
+ % end
56
67
57
68
% for pointer in ['sptr', 'uptr']:
58
69
% for Size in ['16', '32', '64']:
59
70
60
71
% if Size == TestPtrSize:
61
72
int_${TestPtrSize}_ptr_func(${pointer}) // expected-error {{}}
62
73
uint_${TestPtrSize}_ptr_func(${pointer}) // expected-error {{}}
74
+ opt_int_${TestPtrSize}_ptr_func(${pointer}) // expected-error {{}}
75
+ opt_uint_${TestPtrSize}_ptr_func(${pointer}) // expected-error {{}}
63
76
64
77
const_int_${TestPtrSize}_ptr_func(${pointer}) // Ok
65
78
const_uint_${TestPtrSize}_ptr_func(${pointer}) // Ok
79
+ const_opt_int_${TestPtrSize}_ptr_func(${pointer}) // Ok
80
+ const_opt_uint_${TestPtrSize}_ptr_func(${pointer}) // Ok
66
81
% else:
67
82
int_${Size}_ptr_func(${pointer}) // expected-error {{}}
68
83
uint_${Size}_ptr_func(${pointer}) // expected-error {{}}
84
+ opt_int_${Size}_ptr_func(${pointer}) // expected-error {{}}
85
+ opt_uint_${Size}_ptr_func(${pointer}) // expected-error {{}}
69
86
70
87
const_int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
71
88
const_uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
89
+ const_opt_int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
90
+ const_opt_uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
72
91
% end
73
92
% end
74
93
% end
94
+
95
+
96
+ % for pointer in ['osptr', 'ouptr']:
97
+ % for Size in ['16', '32', '64']:
98
+ % if Size == TestPtrSize:
99
+ opt_int_${TestPtrSize}_ptr_func(${pointer}) // expected-error {{}}
100
+ opt_uint_${TestPtrSize}_ptr_func(${pointer}) // expected-error {{}}
101
+ const_opt_int_${TestPtrSize}_ptr_func(${pointer}) // Ok
102
+ const_opt_uint_${TestPtrSize}_ptr_func(${pointer}) // Ok
103
+ % else:
104
+ opt_int_${Size}_ptr_func(${pointer}) // expected-error {{}}
105
+ opt_uint_${Size}_ptr_func(${pointer}) // expected-error {{}}
106
+ const_opt_int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
107
+ const_opt_uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
108
+ % end
109
+ % end
110
+ % end
75
111
}
76
112
77
113
% end
@@ -80,37 +116,121 @@ func test_${TestPtrSize}_bit_ptrs(sptr: UnsafePointer<Int${TestPtrSize}>,
80
116
// Mutable pointers can be converted to both immutable and mutable pointers when
81
117
// passed to C/ObjC imported functions.
82
118
func test_mutable_${TestPtrSize}_bit_ptrs(sptr: UnsafeMutablePointer<Int${TestPtrSize}>,
83
- uptr: UnsafeMutablePointer<UInt${TestPtrSize}>) {
84
- char_ptr_func(sptr) // Ok
85
- char_ptr_func(uptr) // Ok
119
+ uptr: UnsafeMutablePointer<UInt${TestPtrSize}>,
120
+ osptr: UnsafeMutablePointer<Int${TestPtrSize}>?,
121
+ ouptr: UnsafeMutablePointer<UInt${TestPtrSize}>?) {
122
+ % for pointer in ['sptr', 'uptr']:
123
+ char_ptr_func(${pointer}) // Ok
124
+ opt_char_ptr_func(${pointer}) // Ok
125
+
126
+ const_char_ptr_func(${pointer}) // Ok
127
+ const_opt_char_ptr_func(${pointer}) // Ok
86
128
87
- const_char_ptr_func(sptr ) // Ok
88
- const_char_ptr_func(uptr ) // Ok
129
+ unsigned_char_ptr_func(${pointer} ) // Ok
130
+ opt_unsigned_char_ptr_func(${pointer} ) // Ok
89
131
90
- unsigned_char_ptr_func(sptr) // Ok
91
- unsigned_char_ptr_func(uptr) // Ok
132
+ const_unsigned_char_ptr_func(${pointer}) // Ok
133
+ const_opt_unsigned_char_ptr_func(${pointer}) // Ok
134
+ % end
92
135
93
- const_unsigned_char_ptr_func(sptr) // Ok
94
- const_unsigned_char_ptr_func(uptr) // Ok
136
+ % for pointer in ['osptr', 'ouptr']:
137
+ opt_char_ptr_func(${pointer}) // Ok
138
+ const_opt_char_ptr_func(${pointer}) // Ok
139
+ opt_unsigned_char_ptr_func(${pointer}) // Ok
140
+ const_opt_unsigned_char_ptr_func(${pointer}) // Ok
141
+ % end
95
142
96
143
% for pointer in ['sptr', 'uptr']:
97
144
% for Size in ['16', '32', '64']:
98
145
99
146
% if Size == TestPtrSize:
100
147
int_${TestPtrSize}_ptr_func(${pointer}) // Ok
101
148
uint_${TestPtrSize}_ptr_func(${pointer}) // Ok
149
+ opt_int_${TestPtrSize}_ptr_func(${pointer}) // Ok
150
+ opt_uint_${TestPtrSize}_ptr_func(${pointer}) // Ok
102
151
103
152
const_int_${TestPtrSize}_ptr_func(${pointer}) // Ok
104
153
const_uint_${TestPtrSize}_ptr_func(${pointer}) // Ok
154
+ const_opt_int_${TestPtrSize}_ptr_func(${pointer}) // Ok
155
+ const_opt_uint_${TestPtrSize}_ptr_func(${pointer}) // Ok
105
156
% else:
106
157
int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
107
158
uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
159
+ opt_int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
160
+ opt_uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
108
161
109
162
const_int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
110
163
const_uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
164
+ const_opt_int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
165
+ const_opt_uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
166
+ % end
167
+ % end
168
+ % end
169
+
170
+ % for pointer in ['osptr', 'ouptr']:
171
+ % for Size in ['16', '32', '64']:
172
+ % if Size == TestPtrSize:
173
+ opt_int_${TestPtrSize}_ptr_func(${pointer}) // Ok
174
+ opt_uint_${TestPtrSize}_ptr_func(${pointer}) // Ok
175
+ const_opt_int_${TestPtrSize}_ptr_func(${pointer}) // Ok
176
+ const_opt_uint_${TestPtrSize}_ptr_func(${pointer}) // Ok
177
+ % else:
178
+ opt_int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
179
+ opt_uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
180
+ const_opt_int_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
181
+ const_opt_uint_${Size}_ptr_func(${pointer}) // expected-error {{}} expected-note {{}}
182
+ % end
111
183
% end
112
184
% end
113
- % end
114
185
}
115
186
116
187
% end
188
+
189
+ func test_raw_ptr_value_to_optional_promotion(
190
+ riptr: UnsafeRawPointer,
191
+ rmptr: UnsafeMutableRawPointer) {
192
+ opt_char_ptr_func(riptr) // expected-error {{}}
193
+ const_opt_char_ptr_func(riptr) // Ok
194
+
195
+ opt_char_ptr_func(rmptr) // Ok
196
+ const_opt_char_ptr_func(rmptr) // Ok
197
+
198
+ opt_unsigned_char_ptr_func(riptr) // expected-error {{}}
199
+ const_opt_unsigned_char_ptr_func(riptr) // Ok
200
+
201
+ opt_unsigned_char_ptr_func(rmptr) // Ok
202
+ const_opt_unsigned_char_ptr_func(rmptr) // Ok
203
+
204
+ % for Ptr in ['riptr', 'rmptr']:
205
+ % for Size in ['16', '32', '64']:
206
+ opt_int_${Size}_ptr_func(${Ptr}) // expected-error {{}}
207
+ opt_uint_${Size}_ptr_func(${Ptr}) // expected-error {{}}
208
+
209
+ const_opt_int_${Size}_ptr_func(${Ptr}) // expected-error {{}}
210
+ const_opt_uint_${Size}_ptr_func(${Ptr}) // expected-error {{}}
211
+ % end
212
+ % end
213
+ }
214
+
215
+ func test_raw_ptr_optional_to_optional_conversion(
216
+ riptr: UnsafeRawPointer?,
217
+ rmptr: UnsafeMutableRawPointer?) {
218
+ opt_char_ptr_func(riptr) // expected-error {{}}
219
+ const_opt_char_ptr_func(riptr) // Ok
220
+
221
+ opt_char_ptr_func(rmptr) // Ok
222
+ const_opt_char_ptr_func(rmptr) // Ok
223
+
224
+ opt_unsigned_char_ptr_func(rmptr) // Ok
225
+ const_opt_unsigned_char_ptr_func(rmptr) // Ok
226
+
227
+ % for Ptr in ['riptr', 'rmptr']:
228
+ % for Size in ['16', '32', '64']:
229
+ opt_int_${Size}_ptr_func(${Ptr}) // expected-error {{}}
230
+ opt_uint_${Size}_ptr_func(${Ptr}) // expected-error {{}}
231
+
232
+ const_opt_int_${Size}_ptr_func(${Ptr}) // expected-error {{}}
233
+ const_opt_uint_${Size}_ptr_func(${Ptr}) // expected-error {{}}
234
+ % end
235
+ % end
236
+ }
0 commit comments