@@ -22,6 +22,8 @@ case some(T)
22
22
case none
23
23
}
24
24
25
+ class SuperKlass {}
26
+
25
27
///////////
26
28
// Tests //
27
29
///////////
@@ -174,8 +176,8 @@ bb0(%0 : @owned $Optional<Builtin.NativeObject>):
174
176
}
175
177
176
178
// CHECK-LABEL: Function: 'switch_enum_mismatching_argument_guaranteed_to_owned'
177
- // CHECK: Error! Argument ownership kind does not match switch_enum !
178
- // CHECK: SwitchEnum : switch_enum %0 : $Optional<Builtin.NativeObject>, case #Optional.some!enumelt.1: bb1, case #Optional.none!enumelt: bb2
179
+ // CHECK: Error! Argument ownership kind does not match terminator !
180
+ // CHECK: Terminator : switch_enum %0 : $Optional<Builtin.NativeObject>, case #Optional.some!enumelt.1: bb1, case #Optional.none!enumelt: bb2
179
181
// CHECK: Argument: %2 = argument of bb1 : $Builtin.NativeObject
180
182
// CHECK: Expected convention: guaranteed.
181
183
// CHECK: Actual convention: owned
196
198
}
197
199
198
200
// CHECK-LABEL: Function: 'switch_enum_mismatching_argument_owned_to_guaranteed'
199
- // CHECK: Error! Argument ownership kind does not match switch_enum !
200
- // CHECK: SwitchEnum : switch_enum %0 : $Optional<Builtin.NativeObject>, case #Optional.some!enumelt.1: bb1, case #Optional.none!enumelt: bb2
201
+ // CHECK: Error! Argument ownership kind does not match terminator !
202
+ // CHECK: Terminator : switch_enum %0 : $Optional<Builtin.NativeObject>, case #Optional.some!enumelt.1: bb1, case #Optional.none!enumelt: bb2
201
203
// CHECK: Argument: %2 = argument of bb1 : $Builtin.NativeObject
202
204
// CHECK: Expected convention: owned.
203
205
// CHECK: Actual convention: guaranteed
@@ -235,6 +237,7 @@ bb1(%2 : @guaranteed $Builtin.NativeObject):
235
237
br bb3
236
238
237
239
bb2:
240
+ end_borrow %1 from %0 : $Optional<Builtin.NativeObject>, $Optional<Builtin.NativeObject>
238
241
br bb3
239
242
240
243
bb3:
@@ -243,3 +246,181 @@ bb3:
243
246
return %9999 : $()
244
247
}
245
248
249
+ // CHECK-LABEL: Function: 'checked_cast_br_mismatching_argument_guaranteed_to_owned_1'
250
+ // CHECK: Error! Argument ownership kind does not match terminator!
251
+ // CHECK: Terminator: checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
252
+ // CHECK: Argument: %2 = argument of bb1 : $SuperKlass
253
+ // CHECK: Expected convention: guaranteed.
254
+ // CHECK: Actual convention: owned
255
+
256
+ // CHECK-LABEL: Function: 'checked_cast_br_mismatching_argument_guaranteed_to_owned_1'
257
+ // CHECK: Error! Argument ownership kind does not match terminator!
258
+ // CHECK: Terminator: checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
259
+ // CHECK: Argument: %5 = argument of bb2 : $Builtin.NativeObject
260
+ // CHECK: Expected convention: guaranteed.
261
+ // CHECK: Actual convention: owned
262
+ sil @checked_cast_br_mismatching_argument_guaranteed_to_owned_1 : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
263
+ bb0(%0 : @guaranteed $Builtin.NativeObject):
264
+ checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
265
+
266
+ bb1(%1 : @owned $SuperKlass):
267
+ destroy_value %1 : $SuperKlass
268
+ br bb3
269
+
270
+ bb2(%2 : @owned $Builtin.NativeObject):
271
+ destroy_value %2 : $Builtin.NativeObject
272
+ br bb3
273
+
274
+ bb3:
275
+ %9999 = tuple()
276
+ return %9999 : $()
277
+ }
278
+
279
+ // CHECK-LABEL: Function: 'checked_cast_br_mismatching_argument_guaranteed_to_owned_2'
280
+ // CHECK: Error! Argument ownership kind does not match terminator!
281
+ // CHECK: Terminator: checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
282
+ // CHECK: Argument: %5 = argument of bb2 : $Builtin.NativeObject
283
+ // CHECK: Expected convention: guaranteed.
284
+ // CHECK: Actual convention: owned
285
+ sil @checked_cast_br_mismatching_argument_guaranteed_to_owned_2 : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
286
+ bb0(%0 : @guaranteed $Builtin.NativeObject):
287
+ checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
288
+
289
+ bb1(%1 : @guaranteed $SuperKlass):
290
+ end_borrow_argument %1 : $SuperKlass
291
+ br bb3
292
+
293
+ bb2(%2 : @owned $Builtin.NativeObject):
294
+ destroy_value %2 : $Builtin.NativeObject
295
+ br bb3
296
+
297
+ bb3:
298
+ %9999 = tuple()
299
+ return %9999 : $()
300
+ }
301
+
302
+ // CHECK-LABEL: Function: 'checked_cast_br_mismatching_argument_guaranteed_to_owned_3'
303
+ // CHECK: Error! Argument ownership kind does not match terminator!
304
+ // CHECK: Terminator: checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
305
+ // CHECK: Argument: %2 = argument of bb1 : $SuperKlass
306
+ // CHECK: Expected convention: guaranteed.
307
+ // CHECK: Actual convention: owned
308
+ sil @checked_cast_br_mismatching_argument_guaranteed_to_owned_3 : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
309
+ bb0(%0 : @guaranteed $Builtin.NativeObject):
310
+ checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
311
+
312
+ bb1(%1 : @owned $SuperKlass):
313
+ destroy_value %1 : $SuperKlass
314
+ br bb3
315
+
316
+ bb2(%2 : @guaranteed $Builtin.NativeObject):
317
+ end_borrow_argument %2 : $Builtin.NativeObject
318
+ br bb3
319
+
320
+ bb3:
321
+ %9999 = tuple()
322
+ return %9999 : $()
323
+ }
324
+
325
+ // CHECK-LABEL: Function: 'checked_cast_br_mismatching_argument_owned_to_guaranteed_1'
326
+ // CHECK: Error! Argument ownership kind does not match terminator!
327
+ // CHECK: Terminator: checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
328
+ // CHECK: Argument: %2 = argument of bb1 : $SuperKlass
329
+ // CHECK: Expected convention: owned.
330
+ // CHECK: Actual convention: guaranteed
331
+ // CHECK-LABEL: Function: 'checked_cast_br_mismatching_argument_owned_to_guaranteed_1'
332
+ // CHECK: Error! Argument ownership kind does not match terminator!
333
+ // CHECK: Terminator: checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
334
+ // CHECK: Argument: %5 = argument of bb2 : $Builtin.NativeObject
335
+ // CHECK: Expected convention: owned.
336
+ // CHECK: Actual convention: guaranteed
337
+ sil @checked_cast_br_mismatching_argument_owned_to_guaranteed_1 : $@convention(thin) (@owned Builtin.NativeObject) -> () {
338
+ bb0(%0 : @owned $Builtin.NativeObject):
339
+ checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
340
+
341
+ bb1(%1 : @guaranteed $SuperKlass):
342
+ end_borrow_argument %1 : $SuperKlass
343
+ br bb3
344
+
345
+ bb2(%2 : @guaranteed $Builtin.NativeObject):
346
+ end_borrow_argument %2 : $Builtin.NativeObject
347
+ br bb3
348
+
349
+ bb3:
350
+ %9999 = tuple()
351
+ return %9999 : $()
352
+ }
353
+
354
+
355
+ // CHECK-LABEL: Function: 'checked_cast_br_mismatching_argument_owned_to_guaranteed_2'
356
+ // CHECK: Error! Argument ownership kind does not match terminator!
357
+ // CHECK: Terminator: checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
358
+ // CHECK: Argument: %2 = argument of bb1 : $SuperKlass
359
+ // CHECK: Expected convention: owned.
360
+ // CHECK: Actual convention: guaranteed
361
+ sil @checked_cast_br_mismatching_argument_owned_to_guaranteed_2 : $@convention(thin) (@owned Builtin.NativeObject) -> () {
362
+ bb0(%0 : @owned $Builtin.NativeObject):
363
+ checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
364
+
365
+ bb1(%1 : @guaranteed $SuperKlass):
366
+ end_borrow_argument %1 : $SuperKlass
367
+ br bb3
368
+
369
+ bb2(%2 : @owned $Builtin.NativeObject):
370
+ destroy_value %2 : $Builtin.NativeObject
371
+ br bb3
372
+
373
+ bb3:
374
+ %9999 = tuple()
375
+ return %9999 : $()
376
+ }
377
+
378
+ // CHECK-LABEL: Function: 'checked_cast_br_mismatching_argument_owned_to_guaranteed_3'
379
+ // CHECK: Error! Argument ownership kind does not match terminator!
380
+ // CHECK: Terminator: checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
381
+ // CHECK: Argument: %5 = argument of bb2 : $Builtin.NativeObject
382
+ // CHECK: Expected convention: owned.
383
+ // CHECK: Actual convention: guaranteed
384
+ sil @checked_cast_br_mismatching_argument_owned_to_guaranteed_3 : $@convention(thin) (@owned Builtin.NativeObject) -> () {
385
+ bb0(%0 : @owned $Builtin.NativeObject):
386
+ checked_cast_br %0 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
387
+
388
+ bb1(%1 : @owned $SuperKlass):
389
+ destroy_value %1 : $SuperKlass
390
+ br bb3
391
+
392
+ bb2(%2 : @guaranteed $Builtin.NativeObject):
393
+ end_borrow_argument %2 : $Builtin.NativeObject
394
+ br bb3
395
+
396
+ bb3:
397
+ %9999 = tuple()
398
+ return %9999 : $()
399
+ }
400
+
401
+ // CHECK-LABEL: Function: 'checked_cast_br_guaranteed_arg_outlives_original_value'
402
+ // CHECK: Found use after free?!
403
+ // CHECK: Value: %1 = begin_borrow %0 : $Builtin.NativeObject
404
+ // CHECK: Consuming User: end_borrow %1 from %0 : $Builtin.NativeObject, $Builtin.NativeObject
405
+ // CHECK: Non Consuming User: end_borrow_argument %7 : $Builtin.NativeObject
406
+ // CHECK: Block: bb2
407
+ sil @checked_cast_br_guaranteed_arg_outlives_original_value : $@convention(thin) (@owned Builtin.NativeObject) -> () {
408
+ bb0(%0 : @owned $Builtin.NativeObject):
409
+ %1 = begin_borrow %0 : $Builtin.NativeObject
410
+ checked_cast_br %1 : $Builtin.NativeObject to $SuperKlass, bb1, bb2
411
+
412
+ bb1(%2 : @guaranteed $SuperKlass):
413
+ end_borrow_argument %2 : $SuperKlass
414
+ end_borrow %1 from %0 : $Builtin.NativeObject, $Builtin.NativeObject
415
+ br bb3
416
+
417
+ bb2(%3 : @guaranteed $Builtin.NativeObject):
418
+ end_borrow %1 from %0 : $Builtin.NativeObject, $Builtin.NativeObject
419
+ end_borrow_argument %3 : $Builtin.NativeObject
420
+ br bb3
421
+
422
+ bb3:
423
+ destroy_value %0 : $Builtin.NativeObject
424
+ %9999 = tuple()
425
+ return %9999 : $()
426
+ }
0 commit comments