Skip to content

Commit 13d48d2

Browse files
committed
[region-isolation] Add support for explicit_copy_value as a look through instruction.
1 parent b178843 commit 13d48d2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ static SILValue getUnderlyingTrackedObjectValue(SILValue value) {
199199

200200
temp = getUnderlyingObject(temp);
201201

202+
if (auto *cvi = dyn_cast<ExplicitCopyValueInst>(temp)) {
203+
temp = cvi->getOperand();
204+
}
205+
202206
if (auto *dsi = dyn_cast_or_null<DestructureStructInst>(
203207
temp->getDefiningInstruction())) {
204208
temp = dsi->getOperand();
@@ -2312,6 +2316,7 @@ CONSTANT_TRANSLATION(BeginDeallocRefInst, LookThrough)
23122316
CONSTANT_TRANSLATION(RefToBridgeObjectInst, LookThrough)
23132317
CONSTANT_TRANSLATION(BridgeObjectToRefInst, LookThrough)
23142318
CONSTANT_TRANSLATION(CopyValueInst, LookThrough)
2319+
CONSTANT_TRANSLATION(ExplicitCopyValueInst, LookThrough)
23152320
CONSTANT_TRANSLATION(EndCOWMutationInst, LookThrough)
23162321
CONSTANT_TRANSLATION(ProjectBoxInst, LookThrough)
23172322
CONSTANT_TRANSLATION(EndInitLetRefInst, LookThrough)
@@ -2385,7 +2390,6 @@ CONSTANT_TRANSLATION(ObjCMetatypeToObjectInst, Unhandled)
23852390
CONSTANT_TRANSLATION(ObjCExistentialMetatypeToObjectInst, Unhandled)
23862391
CONSTANT_TRANSLATION(ClassifyBridgeObjectInst, Unhandled)
23872392
CONSTANT_TRANSLATION(ValueToBridgeObjectInst, Unhandled)
2388-
CONSTANT_TRANSLATION(ExplicitCopyValueInst, Unhandled)
23892393
CONSTANT_TRANSLATION(UnownedCopyValueInst, Unhandled)
23902394
CONSTANT_TRANSLATION(WeakCopyValueInst, Unhandled)
23912395
CONSTANT_TRANSLATION(StrongCopyWeakValueInst, Unhandled)

test/Concurrency/sendnonsendable_basic.sil

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,20 @@ bb3:
8888
%9999 = tuple ()
8989
return %9999 : $()
9090
}
91+
92+
sil [ossa] @explicit_copy_value_test : $@convention(thin) @async () -> () {
93+
bb0:
94+
%0 = function_ref @constructKlass : $@convention(thin) () -> @owned NonSendableKlass
95+
%1 = apply %0() : $@convention(thin) () -> @owned NonSendableKlass
96+
%2 = function_ref @transferKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
97+
%1a = explicit_copy_value %1 : $NonSendableKlass
98+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %2(%1a) : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
99+
// expected-warning @-1 {{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}}
100+
%3 = function_ref @useKlass : $@convention(thin) (@guaranteed NonSendableKlass) -> ()
101+
apply %3(%1) : $@convention(thin) (@guaranteed NonSendableKlass) -> ()
102+
// expected-note @-1 {{access here could race}}
103+
destroy_value %1a : $NonSendableKlass
104+
destroy_value %1 : $NonSendableKlass
105+
%9999 = tuple ()
106+
return %9999 : $()
107+
}

0 commit comments

Comments
 (0)