Skip to content

Commit f6cda45

Browse files
committed
[region-isolation] Add support for alloc_vector. Its an assign fresh.
1 parent 58a6e2a commit f6cda45

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,7 @@ CONSTANT_TRANSLATION(AllocPackInst, AssignFresh)
22642264
CONSTANT_TRANSLATION(AllocRefDynamicInst, AssignFresh)
22652265
CONSTANT_TRANSLATION(AllocRefInst, AssignFresh)
22662266
CONSTANT_TRANSLATION(AllocStackInst, AssignFresh)
2267+
CONSTANT_TRANSLATION(AllocVectorInst, AssignFresh)
22672268
CONSTANT_TRANSLATION(KeyPathInst, AssignFresh)
22682269
CONSTANT_TRANSLATION(FunctionRefInst, AssignFresh)
22692270
CONSTANT_TRANSLATION(DynamicFunctionRefInst, AssignFresh)
@@ -2408,7 +2409,6 @@ CONSTANT_TRANSLATION(SwitchEnumAddrInst, Require)
24082409
CONSTANT_TRANSLATION(YieldInst, Require)
24092410

24102411
// Unhandled instructions
2411-
CONSTANT_TRANSLATION(AllocVectorInst, Unhandled)
24122412
CONSTANT_TRANSLATION(AllocExistentialBoxInst, Unhandled)
24132413
CONSTANT_TRANSLATION(IndexRawPointerInst, Unhandled)
24142414
CONSTANT_TRANSLATION(UncheckedTrivialBitCastInst, Unhandled)

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
sil_stage raw
1313

1414
import Swift
15+
import Builtin
1516

1617
class NonSendableKlass {}
1718

@@ -330,3 +331,25 @@ bb0:
330331
%9999 = tuple ()
331332
return %9999 : $()
332333
}
334+
335+
sil [ossa] @alloc_vector_test : $@convention(thin) @async () -> () {
336+
bb0:
337+
%0 = function_ref @constructKlass : $@convention(thin) () -> @owned NonSendableKlass
338+
%1 = apply %0() : $@convention(thin) () -> @owned NonSendableKlass
339+
%2 = integer_literal $Builtin.Word, 5
340+
%3 = alloc_vector $NonSendableKlass, %2 : $Builtin.Word
341+
store %1 to [init] %3 : $*NonSendableKlass
342+
343+
%4 = function_ref @transferIndirect : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
344+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %4<NonSendableKlass>(%3) : $@convention(thin) @async <τ_0_0> (@in_guaranteed τ_0_0) -> ()
345+
// 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}}
346+
347+
%5 = function_ref @useIndirect : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
348+
apply %5<NonSendableKlass>(%3) : $@convention(thin) <τ_0_0> (@in_guaranteed τ_0_0) -> ()
349+
// expected-note @-1 {{access here could race}}
350+
351+
destroy_addr %3 : $*NonSendableKlass
352+
dealloc_stack %3 : $*NonSendableKlass
353+
%9999 = tuple ()
354+
return %9999 : $()
355+
}

0 commit comments

Comments
 (0)