Skip to content

Commit 4414636

Browse files
committed
[region-isolation] Add support for bind_memory and rebind_memory.
1 parent 62a64d3 commit 4414636

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,6 +2395,8 @@ CONSTANT_TRANSLATION(MarkFunctionEscapeInst, Require)
23952395
CONSTANT_TRANSLATION(UnmanagedRetainValueInst, Require)
23962396
CONSTANT_TRANSLATION(UnmanagedReleaseValueInst, Require)
23972397
CONSTANT_TRANSLATION(UnmanagedAutoreleaseValueInst, Require)
2398+
CONSTANT_TRANSLATION(RebindMemoryInst, Require)
2399+
CONSTANT_TRANSLATION(BindMemoryInst, Require)
23982400

23992401
//===---
24002402
// Terminators
@@ -2464,8 +2466,6 @@ CONSTANT_TRANSLATION(DifferentiabilityWitnessFunctionInst, Unhandled)
24642466
CONSTANT_TRANSLATION(GetAsyncContinuationInst, Unhandled)
24652467
CONSTANT_TRANSLATION(GetAsyncContinuationAddrInst, Unhandled)
24662468
CONSTANT_TRANSLATION(ExtractExecutorInst, Unhandled)
2467-
CONSTANT_TRANSLATION(BindMemoryInst, Unhandled)
2468-
CONSTANT_TRANSLATION(RebindMemoryInst, Unhandled)
24692469
CONSTANT_TRANSLATION(BeginUnpairedAccessInst, Unhandled)
24702470
CONSTANT_TRANSLATION(EndUnpairedAccessInst, Unhandled)
24712471

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ sil @transferStruct : $@convention(thin) @async (@guaranteed NonSendableStruct)
5858

5959
sil @transferRawPointer : $@convention(thin) @async (Builtin.RawPointer) -> ()
6060
sil @useRawPointer : $@convention(thin) (Builtin.RawPointer) -> ()
61+
sil @initRawPointer : $@convention(thin) () -> Builtin.RawPointer
6162

6263
sil @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
6364
sil @useIndirect : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
@@ -1381,4 +1382,28 @@ sil [ossa] @throw_addr_test : $@convention(thin) @async <E where E : Error> (@in
13811382
bb0(%result : $*NonSendableKlass, %result2 : $*E, %arg : $*E):
13821383
copy_addr %arg to [init] %result2 : $*E
13831384
throw_addr
1385+
}
1386+
1387+
sil [ossa] @bind_memory_test : $@convention(thin) @async () -> () {
1388+
bb0:
1389+
%0 = function_ref @initRawPointer : $@convention(thin) () -> Builtin.RawPointer
1390+
%1 = apply %0() : $@convention(thin) () -> Builtin.RawPointer
1391+
%2 = function_ref @transferRawPointer : $@convention(thin) @async (Builtin.RawPointer) -> ()
1392+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %2(%1) : $@convention(thin) @async (Builtin.RawPointer) -> () // expected-warning {{transferring value of non-Sendable type 'Builtin.RawPointer' from nonisolated context to global actor '<null>'-isolated context; later accesses could race}}
1393+
%4 = integer_literal $Builtin.Word, 1
1394+
%5 = bind_memory %1 : $Builtin.RawPointer, %4 : $Builtin.Word to $NonSendableKlass // expected-note {{access here could race}}
1395+
%9999 = tuple ()
1396+
return %9999 : $()
1397+
}
1398+
1399+
sil [ossa] @rebind_memory_test : $@convention(thin) @async () -> () {
1400+
bb0:
1401+
%0 = function_ref @initRawPointer : $@convention(thin) () -> Builtin.RawPointer
1402+
%1 = apply %0() : $@convention(thin) () -> Builtin.RawPointer
1403+
%2 = function_ref @transferRawPointer : $@convention(thin) @async (Builtin.RawPointer) -> ()
1404+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %2(%1) : $@convention(thin) @async (Builtin.RawPointer) -> () // expected-warning {{transferring value of non-Sendable type 'Builtin.RawPointer' from nonisolated context to global actor '<null>'-isolated context; later accesses could race}}
1405+
%4 = integer_literal $Builtin.Word, 1
1406+
%5 = rebind_memory %1 : $Builtin.RawPointer to %4 : $Builtin.Word // expected-note {{access here could race}}
1407+
%9999 = tuple ()
1408+
return %9999 : $()
13841409
}

0 commit comments

Comments
 (0)