Skip to content

Commit 647c63c

Browse files
committed
[sil] Add support for cloning unmanaged_autorelease_value from ossa funcs into non-ossa funcs.
1 parent c12e556 commit 647c63c

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,13 @@ template <typename ImplClass>
17011701
void SILCloner<ImplClass>::visitUnmanagedAutoreleaseValueInst(
17021702
UnmanagedAutoreleaseValueInst *Inst) {
17031703
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
1704+
if (!getBuilder().hasOwnership()) {
1705+
return recordClonedInstruction(Inst, getBuilder().createAutoreleaseValue(
1706+
getOpLocation(Inst->getLoc()),
1707+
getOpValue(Inst->getOperand()),
1708+
Inst->getAtomicity()));
1709+
}
1710+
17041711
recordClonedInstruction(Inst, getBuilder().createUnmanagedAutoreleaseValue(
17051712
getOpLocation(Inst->getLoc()),
17061713
getOpValue(Inst->getOperand()),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %target-sil-opt -enable-sil-verify-all %s -mandatory-inlining -enable-sil-ownership | %FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
sil_stage raw
6+
7+
import Builtin
8+
import Swift
9+
import ObjectiveC
10+
11+
//////////////////
12+
// Declarations //
13+
//////////////////
14+
15+
class Klass : NSObject {}
16+
17+
///////////
18+
// Tests //
19+
///////////
20+
21+
// Test out functionality that we use to work around weird semantics of
22+
// destructors.
23+
sil [ossa] [transparent] @unmanaged_rr_callee : $@convention(thin) (@guaranteed Klass) -> () {
24+
bb0(%0 : @guaranteed $Klass):
25+
unmanaged_autorelease_value %0 : $Klass
26+
%9999 = tuple()
27+
return %9999 : $()
28+
}
29+
30+
// CHECK-LABEL: sil @unmanaged_rr_caller : $@convention(thin) (@guaranteed Klass) -> () {
31+
// CHECK: bb0([[ARG:%.*]] :
32+
// CHECK-NEXT: autorelease_value [[ARG]]
33+
// CHECK-NEXT: tuple
34+
// CHECK-NEXT: tuple
35+
// CHECK-NEXT: return
36+
// CHECK: } // end sil function 'unmanaged_rr_caller'
37+
sil @unmanaged_rr_caller : $@convention(thin) (@guaranteed Klass) -> () {
38+
bb0(%0 : $Klass):
39+
%1 = function_ref @unmanaged_rr_callee : $@convention(thin) (@guaranteed Klass) -> ()
40+
apply %1(%0) : $@convention(thin) (@guaranteed Klass) -> ()
41+
%9999 = tuple()
42+
return %9999 : $()
43+
}

0 commit comments

Comments
 (0)