@@ -30,6 +30,7 @@ sil @foo_allocating_init : $@convention(thin) (@thick Foo.Type) -> @owned Foo
3030sil @baz_init : $@convention(thin) (@thin Baz.Type) -> @owned Baz
3131sil @dummy_func : $@convention(thin) (Int, Int, Int) -> Int
3232sil @destructured_baz_user : $@convention(thin) (@owned Bar, @guaranteed Bar, Int) -> ()
33+ sil @guaranteed_nativeobject_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
3334
3435// CHECK-LABEL: sil [ossa] @test_capture_promotion
3536sil [ossa] @test_capture_promotion : $@convention(thin) () -> @owned @callee_owned () -> (Int, Builtin.Int64) {
@@ -471,3 +472,36 @@ bb0(%0 : @owned $<τ_0_0> { var τ_0_0 } <Baz>, %1 : @owned $<τ_0_0> { var τ_0
471472 %t = tuple()
472473 return %t : $()
473474}
475+
476+
477+
478+ // Make sure that we properly handle guaranteed arguments when specializing here.
479+ sil [ossa] @capture_promotion_callee_guaranteed_box : $@convention(thin) (@guaranteed { var Builtin.NativeObject }) -> () {
480+ bb0(%0 : @guaranteed ${ var Builtin.NativeObject }):
481+ %1 = project_box %0 : ${ var Builtin.NativeObject }, 0
482+ %2 = begin_access [read] [unknown] %1 : $*Builtin.NativeObject
483+ %3 = load [copy] %2 : $*Builtin.NativeObject
484+ end_access %2 : $*Builtin.NativeObject
485+ %4 = function_ref @guaranteed_nativeobject_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
486+ apply %4(%3) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
487+ destroy_value %3 : $Builtin.NativeObject
488+ %9999 = tuple()
489+ return %9999 : $()
490+ }
491+
492+ // Just make sure that we specialized so that the ownership verifier can make
493+ // sure we emitted ownership correctly.
494+ //
495+ // CHECK-LABEL: sil [ossa] @capture_promotion_caller_guaranteed_box : $@convention(thin) (@owned Builtin.NativeObject) -> @owned @callee_owned () -> () {
496+ // CHECK: [[FUNC_REF:%.*]] = function_ref @$s39capture_promotion_callee_guaranteed_boxTf2i_n :
497+ // CHECK: apply [[FUNC_REF]](
498+ // CHECK: } // end sil function 'capture_promotion_caller_guaranteed_box'
499+ sil [ossa] @capture_promotion_caller_guaranteed_box : $@convention(thin) (@owned Builtin.NativeObject) -> @owned @callee_owned () -> () {
500+ bb0(%0 : @owned $Builtin.NativeObject):
501+ %1 = alloc_box ${ var Builtin.NativeObject }
502+ %2 = project_box %1 : ${ var Builtin.NativeObject }, 0
503+ store %0 to [init] %2 : $*Builtin.NativeObject
504+ %3 = function_ref @capture_promotion_callee_guaranteed_box : $@convention(thin) (@guaranteed { var Builtin.NativeObject }) -> ()
505+ %pai = partial_apply %3(%1) : $@convention(thin) (@guaranteed { var Builtin.NativeObject }) -> ()
506+ return %pai : $@callee_owned () -> ()
507+ }
0 commit comments