File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -79,19 +79,35 @@ bool swift::isOwnershipForwardingInst(SILInstruction *i) {
79
79
80
80
bool swift::getUnderlyingBorrowIntroducers (SILValue inputValue,
81
81
SmallVectorImpl<SILValue> &out) {
82
+ if (inputValue.getOwnershipKind () != ValueOwnershipKind::Guaranteed)
83
+ return false ;
84
+
82
85
SmallVector<SILValue, 32 > worklist;
83
86
worklist.emplace_back (inputValue);
84
87
85
88
while (!worklist.empty ()) {
86
89
SILValue v = worklist.pop_back_val ();
87
90
88
91
// First check if v is an introducer. If so, stash it and continue.
89
- if (isa<SILFunctionArgument>(v) || isa< LoadBorrowInst>(v) ||
92
+ if (isa<LoadBorrowInst>(v) ||
90
93
isa<BeginBorrowInst>(v)) {
91
94
out.push_back (v);
92
95
continue ;
93
96
}
94
97
98
+ // If we have a function argument with guaranteed convention, it is also an
99
+ // introducer.
100
+ if (auto *arg = dyn_cast<SILFunctionArgument>(v)) {
101
+ if (arg->getOwnershipKind () == ValueOwnershipKind::Guaranteed) {
102
+ out.push_back (v);
103
+ continue ;
104
+ }
105
+
106
+ // Otherwise, we do not know how to handle this function argument, so
107
+ // bail.
108
+ return false ;
109
+ }
110
+
95
111
// Otherwise if v is an ownership forwarding value, add its defining
96
112
// instruction
97
113
if (isGuaranteedForwardingValue (v)) {
Original file line number Diff line number Diff line change @@ -172,3 +172,19 @@ bb0(%0 : @guaranteed $Builtin.NativeObject):
172
172
%9999 = tuple()
173
173
return %9999 : $()
174
174
}
175
+
176
+ // Do not eliminate a copy from an unowned value. This will cause us to pass the
177
+ // unowned value as guaranteed... =><=.
178
+ //
179
+ // CHECK-LABEL: sil @unowned_arg_copy : $@convention(thin) (Builtin.NativeObject) -> () {
180
+ // CHECK: copy_value
181
+ // CHECK: } // end sil function 'unowned_arg_copy'
182
+ sil @unowned_arg_copy : $@convention(thin) (Builtin.NativeObject) -> () {
183
+ bb0(%0 : @unowned $Builtin.NativeObject):
184
+ %1 = copy_value %0 : $Builtin.NativeObject
185
+ %2 = function_ref @guaranteed_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
186
+ apply %2(%1) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
187
+ destroy_value %1 : $Builtin.NativeObject
188
+ %9999 = tuple()
189
+ return %9999 : $()
190
+ }
You can’t perform that action at this time.
0 commit comments