@@ -469,6 +469,43 @@ bb0(%0 : $Int):
469469 unreachable
470470}
471471
472+ sil [ossa] @closureWithBoxArg : $@convention(thin) (@guaranteed { var SomeClass }) -> () {
473+ bb0(%0 : @guaranteed ${ var SomeClass }):
474+ %r = tuple ()
475+ return %r : $()
476+ }
477+
478+ sil [ossa] @useClosure : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> () {
479+ bb0(%0 : @guaranteed $@callee_guaranteed () -> ()):
480+ %r = tuple ()
481+ return %r : $()
482+ }
483+
484+ // CHECK-LABEL: sil [ossa] @finalReleaseWithBorrow
485+ // CHECK: [[S:%[0-9]+]] = alloc_stack {{.*}}$SomeClass
486+ // CHECK-NOT: destroy_addr
487+ // CHECK: [[F:%[0-9]+]] = function_ref @useClosure
488+ // CHECK: apply [[F]]
489+ // CHECK: destroy_addr [[S]]
490+ // CHECK: } // end sil function 'finalReleaseWithBorrow'
491+ sil [ossa] @finalReleaseWithBorrow : $@convention(thin) (@owned SomeClass) -> () {
492+ bb0(%0 : @owned $SomeClass):
493+ %1 = alloc_box $ { var SomeClass }
494+ %2 = begin_borrow %1 : ${ var SomeClass }
495+ %1a = project_box %2 : ${ var SomeClass }, 0
496+ store %0 to [init] %1a : $*SomeClass
497+ %3 = function_ref @closureWithBoxArg : $@convention(thin) (@guaranteed { var SomeClass }) -> ()
498+ %4 = copy_value %2 : ${ var SomeClass }
499+ %5 = partial_apply [callee_guaranteed] %3(%4) : $@convention(thin) (@guaranteed { var SomeClass }) -> ()
500+ end_borrow %2 : ${ var SomeClass }
501+ destroy_value %1 : ${ var SomeClass }
502+ %6 = function_ref @useClosure : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
503+ apply %6(%5) : $@convention(thin) (@guaranteed @callee_guaranteed () -> ()) -> ()
504+ destroy_value %5 : $@callee_guaranteed () -> ()
505+ %10 = tuple ()
506+ return %10 : $()
507+ }
508+
472509// CHECK-LABEL: sil [transparent] [serialized] [ossa] @mightApply : $@convention(thin) <U where U : P> (@owned @callee_owned () -> @out U) -> ()
473510sil [transparent] [serialized] [ossa] @mightApply : $@convention(thin) <U where U : P> (@owned @callee_owned () -> @out U) -> () {
474511// CHECK: bb0
0 commit comments