Skip to content

Commit b107a18

Browse files
committed
[region-isolation] Handle BeginCowMutation.
1 parent c28ad4e commit b107a18

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
192192
return false;
193193
case SILInstructionKind::BeginAccessInst:
194194
case SILInstructionKind::BeginBorrowInst:
195+
case SILInstructionKind::BeginCOWMutationInst:
195196
case SILInstructionKind::BeginDeallocRefInst:
196197
case SILInstructionKind::BridgeObjectToRefInst:
197198
case SILInstructionKind::CopyValueInst:
@@ -2306,6 +2307,7 @@ CONSTANT_TRANSLATION(UnownedToRefInst, LookThrough)
23062307
CONSTANT_TRANSLATION(UnownedCopyValueInst, LookThrough)
23072308
CONSTANT_TRANSLATION(DropDeinitInst, LookThrough)
23082309
CONSTANT_TRANSLATION(ValueToBridgeObjectInst, LookThrough)
2310+
CONSTANT_TRANSLATION(BeginCOWMutationInst, LookThrough)
23092311

23102312
//===---
23112313
// Store
@@ -2452,7 +2454,6 @@ CONSTANT_TRANSLATION(DeinitExistentialValueInst, Unhandled)
24522454
CONSTANT_TRANSLATION(UnconditionalCheckedCastAddrInst, Unhandled)
24532455
CONSTANT_TRANSLATION(UncheckedRefCastAddrInst, Unhandled)
24542456
CONSTANT_TRANSLATION(PackElementSetInst, Unhandled)
2455-
CONSTANT_TRANSLATION(BeginCOWMutationInst, Unhandled)
24562457

24572458
//===---
24582459
// Apply

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,3 +1188,25 @@ bb0:
11881188
%9999 = tuple ()
11891189
return %9999 : $()
11901190
}
1191+
1192+
sil [ossa] @begin_cow_mutation : $@async @convention(thin) () -> () {
1193+
bb0:
1194+
%0 = function_ref @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
1195+
%1 = apply %0() : $@convention(thin) () -> @owned NonSendableKlass
1196+
%2a = copy_value %1 : $NonSendableKlass
1197+
(%uniq, %2) = begin_cow_mutation %2a : $NonSendableKlass
1198+
%f = function_ref @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
1199+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %f(%1) : $@convention(thin) @async (@guaranteed NonSendableKlass) -> () // expected-warning {{transferring value of non-Sendable type 'NonSendableKlass' from nonisolated context to global actor '<null>'-isolated context; later accesses could race}}
1200+
destroy_value %2 : $NonSendableKlass
1201+
1202+
%3a = copy_value %1 : $NonSendableKlass
1203+
(%uniq2, %3) = begin_cow_mutation %3a : $NonSendableKlass
1204+
%f3 = function_ref @useNonSendableKlass : $@convention(thin) (@guaranteed NonSendableKlass) -> ()
1205+
apply %f3(%3) : $@convention(thin) (@guaranteed NonSendableKlass) -> () // expected-note {{access here could race}}
1206+
destroy_value %3 : $NonSendableKlass
1207+
1208+
destroy_value %1 : $NonSendableKlass
1209+
%9999 = tuple ()
1210+
return %9999 : $()
1211+
}
1212+

0 commit comments

Comments
 (0)