@@ -69,6 +69,18 @@ sil @finalizeSingleTrivialFieldAndDeinit : $@convention(thin) (@owned SingleTriv
69
69
sil_global hidden @$s23moveonly_addresschecker9varGlobalAA16NonTrivialStructVvp : $NonTrivialStruct
70
70
sil_global hidden [let] @$s23moveonly_addresschecker9letGlobalAA16NonTrivialStructVvp : $NonTrivialStruct
71
71
72
+ struct NonCopyableNativeObjectIntPair : ~Copyable {
73
+ var a: Builtin.NativeObject
74
+ var currentPosition: Int
75
+ }
76
+
77
+ struct NonCopyableNativeObjectPair : ~Copyable {
78
+ var a: Builtin.NativeObject
79
+ var currentPosition: Builtin.NativeObject
80
+ }
81
+
82
+ sil @get_nativeobject : $@convention(thin) () -> @owned Builtin.NativeObject
83
+
72
84
///////////
73
85
// Tests //
74
86
///////////
@@ -602,7 +614,7 @@ sil @get_M2 : $@convention(thin) () -> @owned M2
602
614
sil @end_addr_see_addr : $@convention(thin) (@in M, @in_guaranteed M) -> ()
603
615
604
616
/// A single instruction, apply @end_addr_see_addr, consumes one field and
605
- /// borrows another.
617
+ /// borrows another.
606
618
607
619
/// Varify that the consumed value isn't destroyed twice and that the borrowed
608
620
/// value isn't destroyed before it's used.
@@ -768,3 +780,67 @@ bb3:
768
780
%9999 = tuple ()
769
781
return %9999 : $()
770
782
}
783
+
784
+ sil @testUseCorrectBitsClosureCallee : $@convention(thin) (Int, @inout_aliasable NonCopyableNativeObjectIntPair) -> Bool
785
+ sil @testUseCorrectBitsClosureUser : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> Bool) -> ()
786
+
787
+ // CHECK-LABEL: sil [ossa] @testUseCorrectBits : $@convention(method) (Int, @inout NonCopyableNativeObjectIntPair) -> () {
788
+ // CHECK-NOT: destroy_addr
789
+ // CHECK: } // end sil function 'testUseCorrectBits'
790
+ sil [ossa] @testUseCorrectBits : $@convention(method) (Int, @inout NonCopyableNativeObjectIntPair) -> () {
791
+ bb0(%0 : $Int, %1a : $*NonCopyableNativeObjectIntPair):
792
+ debug_value %0 : $Int, let, name "index", argno 1
793
+ debug_value %1a : $*NonCopyableNativeObjectIntPair, var, name "self", argno 2, implicit, expr op_deref
794
+ %1 = mark_must_check [consumable_and_assignable] %1a : $*NonCopyableNativeObjectIntPair
795
+ %4 = function_ref @testUseCorrectBitsClosureCallee : $@convention(thin) (Int, @inout_aliasable NonCopyableNativeObjectIntPair) -> Bool
796
+ %5 = partial_apply [callee_guaranteed] [on_stack] %4(%0, %1) : $@convention(thin) (Int, @inout_aliasable NonCopyableNativeObjectIntPair) -> Bool
797
+ %6 = mark_dependence %5 : $@noescape @callee_guaranteed () -> Bool on %1 : $*NonCopyableNativeObjectIntPair
798
+ %7 = function_ref @testUseCorrectBitsClosureUser : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> Bool) -> ()
799
+ %8 = apply %7(%6) : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> Bool) -> ()
800
+ %9 = struct_element_addr %1 : $*NonCopyableNativeObjectIntPair, #NonCopyableNativeObjectIntPair.currentPosition
801
+ debug_value undef : $*NonCopyableNativeObjectIntPair, var, name "self", argno 2, implicit, expr op_deref
802
+ destroy_value %6 : $@noescape @callee_guaranteed () -> Bool
803
+ %12 = begin_access [modify] [static] %1 : $*NonCopyableNativeObjectIntPair
804
+ %13 = struct_element_addr %12 : $*NonCopyableNativeObjectIntPair, #NonCopyableNativeObjectIntPair.currentPosition
805
+ store %0 to [trivial] %13 : $*Int
806
+ end_access %12 : $*NonCopyableNativeObjectIntPair
807
+ %16 = tuple ()
808
+ return %16 : $()
809
+ }
810
+
811
+ sil @testUseCorrectBits2ClosureCallee : $@convention(thin) (Int, @inout_aliasable NonCopyableNativeObjectPair) -> Bool
812
+
813
+ // CHECK-LABEL: sil [ossa] @testUseCorrectBits2 : $@convention(method) (Int, @inout NonCopyableNativeObjectPair) -> () {
814
+ // CHECK: bb0({{%.*}} : $Int, [[ARG:%.*]] : $*
815
+ // CHECK-NOT: destroy_addr
816
+ // CHECK: [[ACCESS:%.*]] = begin_access [modify] [static] [[ARG]]
817
+ // CHECK-NEXT: [[GEP:%.*]] = struct_element_addr [[ACCESS]]
818
+ // CHECK-NEXT: function_ref get_nativeobject
819
+ // CHECK-NEXT: function_ref @get_nativeobject
820
+ // CHECK-NEXT: apply {{%.*}}
821
+ // CHECK-NEXT: [[GEP2:%.*]] = struct_element_addr [[ARG]] : $*NonCopyableNativeObjectPair, #NonCopyableNativeObjectPair.currentPosition
822
+ // CHECK-NEXT: destroy_addr [[GEP2]]
823
+ // CHECK-NOT: destroy_addr
824
+ // CHECK: } // end sil function 'testUseCorrectBits2'
825
+ sil [ossa] @testUseCorrectBits2 : $@convention(method) (Int, @inout NonCopyableNativeObjectPair) -> () {
826
+ bb0(%0 : $Int, %1a : $*NonCopyableNativeObjectPair):
827
+ debug_value %0 : $Int, let, name "index", argno 1
828
+ debug_value %1a : $*NonCopyableNativeObjectPair, var, name "self", argno 2, implicit, expr op_deref
829
+ %1 = mark_must_check [consumable_and_assignable] %1a : $*NonCopyableNativeObjectPair
830
+ %4 = function_ref @testUseCorrectBits2ClosureCallee : $@convention(thin) (Int, @inout_aliasable NonCopyableNativeObjectPair) -> Bool
831
+ %5 = partial_apply [callee_guaranteed] [on_stack] %4(%0, %1) : $@convention(thin) (Int, @inout_aliasable NonCopyableNativeObjectPair) -> Bool
832
+ %6 = mark_dependence %5 : $@noescape @callee_guaranteed () -> Bool on %1 : $*NonCopyableNativeObjectPair
833
+ %7 = function_ref @testUseCorrectBitsClosureUser : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> Bool) -> ()
834
+ %8 = apply %7(%6) : $@convention(thin) (@guaranteed @noescape @callee_guaranteed () -> Bool) -> ()
835
+ %9 = struct_element_addr %1 : $*NonCopyableNativeObjectPair, #NonCopyableNativeObjectPair.currentPosition
836
+ debug_value undef : $*NonCopyableNativeObjectPair, var, name "self", argno 2, implicit, expr op_deref
837
+ destroy_value %6 : $@noescape @callee_guaranteed () -> Bool
838
+ %12 = begin_access [modify] [static] %1 : $*NonCopyableNativeObjectPair
839
+ %13 = struct_element_addr %12 : $*NonCopyableNativeObjectPair, #NonCopyableNativeObjectPair.currentPosition
840
+ %f = function_ref @get_nativeobject : $@convention(thin) () -> @owned Builtin.NativeObject
841
+ %14 = apply %f() : $@convention(thin) () -> @owned Builtin.NativeObject
842
+ store %14 to [assign] %13 : $*Builtin.NativeObject
843
+ end_access %12 : $*NonCopyableNativeObjectPair
844
+ %16 = tuple ()
845
+ return %16 : $()
846
+ }
0 commit comments