Skip to content

Commit 0cd57e4

Browse files
committed
[region-isolation] Add support for unconditional_checked_cast_addr.
1 parent 02ad3de commit 0cd57e4

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ struct UseDefChainVisitor
183183
/// values. We assert that all instructions that are CONSTANT_TRANSLATION
184184
/// LookThrough to make sure they stay in sync.
185185
static bool isStaticallyLookThroughInst(SILInstruction *inst) {
186-
if (auto cast = SILDynamicCastInst::getAs(inst))
187-
if (cast.isRCIdentityPreserving())
188-
return true;
189-
190186
switch (inst->getKind()) {
191187
default:
192188
return false;
@@ -225,6 +221,13 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
225221
case SILInstructionKind::UpcastInst:
226222
case SILInstructionKind::ValueToBridgeObjectInst:
227223
return true;
224+
case SILInstructionKind::UnconditionalCheckedCastInst: {
225+
auto cast = SILDynamicCastInst::getAs(inst);
226+
assert(cast);
227+
if (cast.isRCIdentityPreserving())
228+
return true;
229+
return false;
230+
}
228231
}
229232
}
230233

@@ -2324,6 +2327,7 @@ CONSTANT_TRANSLATION(StoreBorrowInst, Store)
23242327
CONSTANT_TRANSLATION(StoreWeakInst, Store)
23252328
CONSTANT_TRANSLATION(MarkUnresolvedMoveAddrInst, Store)
23262329
CONSTANT_TRANSLATION(UncheckedRefCastAddrInst, Store)
2330+
CONSTANT_TRANSLATION(UnconditionalCheckedCastAddrInst, Store)
23272331

23282332
//===---
23292333
// Ignored
@@ -2451,9 +2455,9 @@ CONSTANT_TRANSLATION(MarkFunctionEscapeInst, Unhandled)
24512455
CONSTANT_TRANSLATION(TestSpecificationInst, Unhandled)
24522456
CONSTANT_TRANSLATION(StoreUnownedInst, Unhandled)
24532457
CONSTANT_TRANSLATION(DeinitExistentialAddrInst, Unhandled)
2458+
CONSTANT_TRANSLATION(PackElementSetInst, Unhandled)
24542459
CONSTANT_TRANSLATION(DeinitExistentialValueInst, Unhandled)
24552460
CONSTANT_TRANSLATION(UnconditionalCheckedCastAddrInst, Unhandled)
2456-
CONSTANT_TRANSLATION(PackElementSetInst, Unhandled)
24572461

24582462
//===---
24592463
// Apply

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,3 +1236,29 @@ bb0:
12361236
return %9999 : $()
12371237
}
12381238

1239+
// Make sure this is a store by erroring on the cast for %a and emitting a
1240+
// second error for %b.
1241+
sil [ossa] @unconditional_checked_cast_addr_test : $@async @convention(thin) () -> () {
1242+
bb0:
1243+
%a = alloc_stack $NonSendableKlass
1244+
%b = alloc_stack $NonSendableKlass
1245+
%initIndirect = function_ref @initIndirect : $@convention(thin) <T> () -> @out T
1246+
apply %initIndirect<NonSendableKlass>(%a) : $@convention(thin) <T> () -> @out T
1247+
1248+
%f = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
1249+
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}}
1250+
1251+
// This is a copy_addr [take] [init] + cast.
1252+
unconditional_checked_cast_addr NonSendableKlass in %a : $*NonSendableKlass to NonSendableKlass in %b : $*NonSendableKlass // expected-note {{access here could race}}
1253+
1254+
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}}
1255+
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}}
1256+
1257+
destroy_addr %b : $*NonSendableKlass
1258+
dealloc_stack %b : $*NonSendableKlass
1259+
dealloc_stack %a : $*NonSendableKlass
1260+
1261+
%9999 = tuple ()
1262+
return %9999 : $()
1263+
}
1264+

0 commit comments

Comments
 (0)