Skip to content

Commit a2566e0

Browse files
committed
[region-isolation] Add SIL test for struct_element_addr and tuple_element_addr.
1 parent 5aec06f commit a2566e0

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ sil @useIndirect : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
4545
sil @constructMoveOnlyStruct : $@convention(thin) () -> @owned NonSendableMoveOnlyStruct
4646
sil @transferMoveOnlyStruct : $@convention(thin) @async (@guaranteed NonSendableMoveOnlyStruct) -> ()
4747

48+
sil @constructStruct : $@convention(thin) () -> @owned NonSendableStruct
49+
sil @transferStruct : $@convention(thin) @async (@guaranteed NonSendableStruct) -> ()
50+
4851
enum FakeOptional<T> {
4952
case none
5053
case some(T)
@@ -912,6 +915,56 @@ bb0:
912915
destroy_addr %a : $*NonSendableKlass
913916
dealloc_stack %a : $*NonSendableKlass
914917

918+
%9999 = tuple ()
919+
return %9999 : $()
920+
}
921+
922+
sil [ossa] @struct_element_addr_test_1 : $@convention(thin) @async () -> () {
923+
bb0:
924+
%0 = function_ref @constructStruct : $@convention(thin) () -> @owned NonSendableStruct
925+
%1 = apply %0() : $@convention(thin) () -> @owned NonSendableStruct
926+
927+
%a = alloc_stack $NonSendableStruct
928+
%1_copy = copy_value %1 : $NonSendableStruct
929+
store %1_copy to [init] %a : $*NonSendableStruct
930+
931+
%f = function_ref @transferStruct : $@convention(thin) @async (@guaranteed NonSendableStruct) -> ()
932+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f(%1) : $@convention(thin) @async (@guaranteed NonSendableStruct) -> () // expected-warning {{passing argument of non-sendable type 'NonSendableStruct' from nonisolated context to global actor '<null>'-isolated context at this call site could yield a race with accesses later in this function}}
933+
934+
%s = struct_element_addr %a : $*NonSendableStruct, #NonSendableStruct.ns
935+
%f2 = function_ref @useIndirect : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
936+
apply %f2<NonSendableKlass>(%s) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-note {{access here could race}}
937+
938+
destroy_addr %a : $*NonSendableStruct
939+
dealloc_stack %a : $*NonSendableStruct
940+
destroy_value %1 : $NonSendableStruct
941+
942+
%9999 = tuple ()
943+
return %9999 : $()
944+
}
945+
946+
sil [ossa] @tuple_element_addr_test_1 : $@convention(thin) @async () -> () {
947+
bb0:
948+
%0 = function_ref @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
949+
%1 = apply %0() : $@convention(thin) () -> @owned NonSendableKlass
950+
951+
%a = alloc_stack $(NonSendableKlass, NonSendableKlass)
952+
%1_copy = copy_value %1 : $NonSendableKlass
953+
%1_copy_copy = copy_value %1 : $NonSendableKlass
954+
%tup = tuple (%1_copy : $NonSendableKlass, %1_copy_copy : $NonSendableKlass)
955+
store %tup to [init] %a : $*(NonSendableKlass, NonSendableKlass)
956+
957+
%f = function_ref @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
958+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f(%1) : $@convention(thin) @async (@guaranteed NonSendableKlass) -> () // expected-warning {{passing argument of non-sendable type 'NonSendableKlass' from nonisolated context to global actor '<null>'-isolated context at this call site could yield a race with accesses later in this function}}
959+
960+
%s = tuple_element_addr %a : $*(NonSendableKlass, NonSendableKlass), 0
961+
%f2 = function_ref @useIndirect : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
962+
apply %f2<NonSendableKlass>(%s) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-note {{access here could race}}
963+
964+
destroy_addr %a : $*(NonSendableKlass, NonSendableKlass)
965+
dealloc_stack %a : $*(NonSendableKlass, NonSendableKlass)
966+
destroy_value %1 : $NonSendableKlass
967+
915968
%9999 = tuple ()
916969
return %9999 : $()
917970
}

0 commit comments

Comments
 (0)