@@ -10,12 +10,15 @@ import Builtin
10
10
11
11
sil @guaranteed_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
12
12
sil @owned_user : $@convention(thin) (@owned Builtin.NativeObject) -> ()
13
+ sil @get_owned_obj : $@convention(thin) () -> @owned Builtin.NativeObject
13
14
14
15
struct NativeObjectPair {
15
16
var obj1 : Builtin.NativeObject
16
17
var obj2 : Builtin.NativeObject
17
18
}
18
19
20
+ sil @get_nativeobject_pair : $@convention(thin) () -> @owned NativeObjectPair
21
+
19
22
class Klass {}
20
23
21
24
struct MyInt {
@@ -702,3 +705,74 @@ bb1:
702
705
return %9999 : $()
703
706
}
704
707
708
+ // CHECK-LABEL: sil [ossa] @begin_borrow_simple : $@convention(thin) () -> () {
709
+ // CHECK-NOT: copy_value
710
+ // CHECK: } // end sil function 'begin_borrow_simple'
711
+ sil [ossa] @begin_borrow_simple : $@convention(thin) () -> () {
712
+ bb0:
713
+ %0 = function_ref @get_nativeobject_pair : $@convention(thin) () -> @owned NativeObjectPair
714
+ %1 = apply %0() : $@convention(thin) () -> @owned NativeObjectPair
715
+ %2 = begin_borrow %1 : $NativeObjectPair
716
+ %3 = struct_extract %2 : $NativeObjectPair, #NativeObjectPair.obj1
717
+ %4 = copy_value %3 : $Builtin.NativeObject
718
+ %5 = function_ref @guaranteed_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
719
+ apply %5(%4) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
720
+ destroy_value %4 : $Builtin.NativeObject
721
+ end_borrow %2 : $NativeObjectPair
722
+ destroy_value %1 : $NativeObjectPair
723
+ %9999 = tuple()
724
+ return %9999 : $()
725
+ }
726
+
727
+ // CHECK-LABEL: sil [ossa] @begin_borrow_fail : $@convention(thin) () -> () {
728
+ // CHECK: copy_value
729
+ // CHECK: } // end sil function 'begin_borrow_fail'
730
+ sil [ossa] @begin_borrow_fail : $@convention(thin) () -> () {
731
+ bb0:
732
+ %0 = function_ref @get_nativeobject_pair : $@convention(thin) () -> @owned NativeObjectPair
733
+ %1 = apply %0() : $@convention(thin) () -> @owned NativeObjectPair
734
+ %2 = begin_borrow %1 : $NativeObjectPair
735
+ %3 = struct_extract %2 : $NativeObjectPair, #NativeObjectPair.obj1
736
+ %4 = copy_value %3 : $Builtin.NativeObject
737
+ %5 = function_ref @guaranteed_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
738
+ apply %5(%4) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
739
+ end_borrow %2 : $NativeObjectPair
740
+ destroy_value %4 : $Builtin.NativeObject
741
+ destroy_value %1 : $NativeObjectPair
742
+ %9999 = tuple()
743
+ return %9999 : $()
744
+ }
745
+
746
+ // CHECK-LABEL: sil [ossa] @load_borrow_simple : $@convention(thin) (@in NativeObjectPair) -> () {
747
+ // CHECK-NOT: copy_value
748
+ // CHECK: } // end sil function 'load_borrow_simple'
749
+ sil [ossa] @load_borrow_simple : $@convention(thin) (@in NativeObjectPair) -> () {
750
+ bb0(%0 : $*NativeObjectPair):
751
+ %2 = load_borrow %0 : $*NativeObjectPair
752
+ %3 = struct_extract %2 : $NativeObjectPair, #NativeObjectPair.obj1
753
+ %4 = copy_value %3 : $Builtin.NativeObject
754
+ %5 = function_ref @guaranteed_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
755
+ apply %5(%4) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
756
+ destroy_value %4 : $Builtin.NativeObject
757
+ end_borrow %2 : $NativeObjectPair
758
+ destroy_addr %0 : $*NativeObjectPair
759
+ %9999 = tuple()
760
+ return %9999 : $()
761
+ }
762
+
763
+ // CHECK-LABEL: sil [ossa] @load_borrow_fail : $@convention(thin) (@in NativeObjectPair) -> () {
764
+ // CHECK: copy_value
765
+ // CHECK: } // end sil function 'load_borrow_fail'
766
+ sil [ossa] @load_borrow_fail : $@convention(thin) (@in NativeObjectPair) -> () {
767
+ bb0(%0 : $*NativeObjectPair):
768
+ %2 = load_borrow %0 : $*NativeObjectPair
769
+ %3 = struct_extract %2 : $NativeObjectPair, #NativeObjectPair.obj1
770
+ %4 = copy_value %3 : $Builtin.NativeObject
771
+ %5 = function_ref @guaranteed_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
772
+ apply %5(%4) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
773
+ end_borrow %2 : $NativeObjectPair
774
+ destroy_value %4 : $Builtin.NativeObject
775
+ destroy_addr %0 : $*NativeObjectPair
776
+ %9999 = tuple()
777
+ return %9999 : $()
778
+ }
0 commit comments