Skip to content

Commit 02ad3de

Browse files
committed
[region-isolation] Add support for unchecked_ref_cast_addr.
1 parent b107a18 commit 02ad3de

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2323,6 +2323,7 @@ CONSTANT_TRANSLATION(StoreInst, Store)
23232323
CONSTANT_TRANSLATION(StoreBorrowInst, Store)
23242324
CONSTANT_TRANSLATION(StoreWeakInst, Store)
23252325
CONSTANT_TRANSLATION(MarkUnresolvedMoveAddrInst, Store)
2326+
CONSTANT_TRANSLATION(UncheckedRefCastAddrInst, Store)
23262327

23272328
//===---
23282329
// Ignored
@@ -2452,7 +2453,6 @@ CONSTANT_TRANSLATION(StoreUnownedInst, Unhandled)
24522453
CONSTANT_TRANSLATION(DeinitExistentialAddrInst, Unhandled)
24532454
CONSTANT_TRANSLATION(DeinitExistentialValueInst, Unhandled)
24542455
CONSTANT_TRANSLATION(UnconditionalCheckedCastAddrInst, Unhandled)
2455-
CONSTANT_TRANSLATION(UncheckedRefCastAddrInst, Unhandled)
24562456
CONSTANT_TRANSLATION(PackElementSetInst, Unhandled)
24572457

24582458
//===---

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,3 +1210,29 @@ bb0:
12101210
return %9999 : $()
12111211
}
12121212

1213+
// Make sure this is a store by erroring on the cast for %a and emitting a
1214+
// second error for %b.
1215+
sil [ossa] @unchecked_ref_cast_addr_test : $@async @convention(thin) () -> () {
1216+
bb0:
1217+
%a = alloc_stack $NonSendableKlass
1218+
%b = alloc_stack $NonSendableKlass
1219+
%initIndirect = function_ref @initIndirect : $@convention(thin) <T> () -> @out T
1220+
apply %initIndirect<NonSendableKlass>(%a) : $@convention(thin) <T> () -> @out T
1221+
1222+
%f = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
1223+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%a) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-warning {{transferring value of non-Sendable type 'NonSendableKlass' from nonisolated context to global actor '<null>'-isolated context}}
1224+
1225+
// This is a copy_addr [take] [init] + cast.
1226+
unchecked_ref_cast_addr NonSendableKlass in %a : $*NonSendableKlass to NonSendableKlass in %b : $*NonSendableKlass // expected-note {{access here could race}}
1227+
1228+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%b) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-warning {{transferring value of non-Sendable type 'NonSendableKlass' from nonisolated context to global actor '<null>'-isolated context}}
1229+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f<NonSendableKlass>(%b) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> () // expected-note {{access here could race}}
1230+
1231+
destroy_addr %b : $*NonSendableKlass
1232+
dealloc_stack %b : $*NonSendableKlass
1233+
dealloc_stack %a : $*NonSendableKlass
1234+
1235+
%9999 = tuple ()
1236+
return %9999 : $()
1237+
}
1238+

0 commit comments

Comments
 (0)