Skip to content

Commit 4218f5b

Browse files
committed
[region-isolation] Teach the checker about unmanaged {retain, release, autorelease}.
1 parent 369f441 commit 4218f5b

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,6 +2372,9 @@ CONSTANT_TRANSLATION(ClassifyBridgeObjectInst, Require)
23722372
CONSTANT_TRANSLATION(BridgeObjectToWordInst, Require)
23732373
CONSTANT_TRANSLATION(IsUniqueInst, Require)
23742374
CONSTANT_TRANSLATION(MarkFunctionEscapeInst, Require)
2375+
CONSTANT_TRANSLATION(UnmanagedRetainValueInst, Require)
2376+
CONSTANT_TRANSLATION(UnmanagedReleaseValueInst, Require)
2377+
CONSTANT_TRANSLATION(UnmanagedAutoreleaseValueInst, Require)
23752378

23762379
//===---
23772380
// Terminators
@@ -2439,9 +2442,6 @@ CONSTANT_TRANSLATION(BindMemoryInst, Unhandled)
24392442
CONSTANT_TRANSLATION(RebindMemoryInst, Unhandled)
24402443
CONSTANT_TRANSLATION(ThrowAddrInst, Unhandled)
24412444
CONSTANT_TRANSLATION(AwaitAsyncContinuationInst, Unhandled)
2442-
CONSTANT_TRANSLATION(UnmanagedRetainValueInst, Unhandled)
2443-
CONSTANT_TRANSLATION(UnmanagedReleaseValueInst, Unhandled)
2444-
CONSTANT_TRANSLATION(UnmanagedAutoreleaseValueInst, Unhandled)
24452445
CONSTANT_TRANSLATION(BeginUnpairedAccessInst, Unhandled)
24462446
CONSTANT_TRANSLATION(EndUnpairedAccessInst, Unhandled)
24472447

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,3 +1316,63 @@ bb0:
13161316
%9999 = tuple ()
13171317
return %9999 : $()
13181318
}
1319+
1320+
sil [ossa] @unmanaged_retain_test : $@convention(thin) @async () -> () {
1321+
bb0:
1322+
%constructFn = function_ref @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
1323+
%value = apply %constructFn() : $@convention(thin) () -> @owned NonSendableKlass
1324+
%a = alloc_stack $NonSendableKlass
1325+
%valueCopy = copy_value %value : $NonSendableKlass
1326+
store %valueCopy to [init] %a : $*NonSendableKlass
1327+
1328+
%transferNonSendableKlass = function_ref @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
1329+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferNonSendableKlass(%value) : $@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}}
1330+
1331+
unmanaged_retain_value %value : $NonSendableKlass // expected-note {{access here could race}}
1332+
destroy_value %value : $NonSendableKlass
1333+
destroy_addr %a : $*NonSendableKlass
1334+
dealloc_stack %a : $*NonSendableKlass
1335+
1336+
%9999 = tuple ()
1337+
return %9999 : $()
1338+
}
1339+
1340+
sil [ossa] @unmanaged_release_test : $@convention(thin) @async () -> () {
1341+
bb0:
1342+
%constructFn = function_ref @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
1343+
%value = apply %constructFn() : $@convention(thin) () -> @owned NonSendableKlass
1344+
%a = alloc_stack $NonSendableKlass
1345+
%valueCopy = copy_value %value : $NonSendableKlass
1346+
store %valueCopy to [init] %a : $*NonSendableKlass
1347+
1348+
%transferNonSendableKlass = function_ref @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
1349+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferNonSendableKlass(%value) : $@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}}
1350+
1351+
unmanaged_release_value %value : $NonSendableKlass // expected-note {{access here could race}}
1352+
destroy_value %value : $NonSendableKlass
1353+
destroy_addr %a : $*NonSendableKlass
1354+
dealloc_stack %a : $*NonSendableKlass
1355+
1356+
%9999 = tuple ()
1357+
return %9999 : $()
1358+
}
1359+
1360+
sil [ossa] @unmanaged_autorelease_test : $@convention(thin) @async () -> () {
1361+
bb0:
1362+
%constructFn = function_ref @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
1363+
%value = apply %constructFn() : $@convention(thin) () -> @owned NonSendableKlass
1364+
%a = alloc_stack $NonSendableKlass
1365+
%valueCopy = copy_value %value : $NonSendableKlass
1366+
store %valueCopy to [init] %a : $*NonSendableKlass
1367+
1368+
%transferNonSendableKlass = function_ref @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
1369+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferNonSendableKlass(%value) : $@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}}
1370+
1371+
unmanaged_autorelease_value %value : $NonSendableKlass // expected-note {{access here could race}}
1372+
destroy_value %value : $NonSendableKlass
1373+
destroy_addr %a : $*NonSendableKlass
1374+
dealloc_stack %a : $*NonSendableKlass
1375+
1376+
%9999 = tuple ()
1377+
return %9999 : $()
1378+
}

0 commit comments

Comments
 (0)