Skip to content

Commit c8ae63f

Browse files
committed
[SILInliner] Removed wrong lexical end borrows.
In 79bc4cb, when -enable-experimental-lexical-lifetimes was passed, every argument marked to receive an end_borrow, although not every argument was borrowed (that part was correct). Fix the mistake by only marking arguments which are actually borrowed as such.
1 parent c2a9272 commit c8ae63f

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,8 @@ SILInlineCloner::cloneInline(ArrayRef<SILValue> AppliedArgs) {
448448
callArg = builder.createCopyValue(Apply.getLoc(), bbi);
449449
copiedArgs[idx] = true;
450450
}
451+
borrowedArgs[idx] = true;
451452
}
452-
borrowedArgs[idx] = true;
453453
} else {
454454
// Insert begin/end borrow for guaranteed arguments.
455455
if (calleeConv.getParamInfoForSILArg(idx).isGuaranteed()) {

test/SILOptimizer/inline_lifetime.sil

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import Swift
44

55
class C {}
66

7+
struct S {}
8+
79
////////////////////////////////////////////////////////////////////////////////
810
// apply
911
////////////////////////////////////////////////////////////////////////////////
@@ -23,6 +25,12 @@ entry(%instance : @guaranteed $C):
2325
return %retval : $()
2426
}
2527

28+
sil [ossa] [always_inline] @callee_trivial : $@convention(thin) (S) -> () {
29+
entry(%instance : $S):
30+
%retval = tuple ()
31+
return %retval : $()
32+
}
33+
2634
// tests
2735

2836
// CHECK-LABEL: sil [ossa] @caller_owned_callee_owned : $@convention(thin) (@owned C) -> () {
@@ -91,6 +99,18 @@ entry(%instance : @guaranteed $C):
9199
return %result : $()
92100
}
93101

102+
// CHECK-LABEL: sil [ossa] @caller_trivial_callee_trivial : $@convention(thin) (S) -> () {
103+
// CHECK: {{bb[^,]+}}({{%[^,]+}} : $S):
104+
// CHECK: [[RETVAL:%[^,]+]] = tuple ()
105+
// CHECK: return [[RETVAL]]
106+
// CHECK-LABEL: } // end sil function 'caller_trivial_callee_trivial'
107+
sil [ossa] @caller_trivial_callee_trivial : $@convention(thin) (S) -> () {
108+
entry(%instance : $S):
109+
%callee_trivial = function_ref @callee_trivial : $@convention(thin) (S) -> ()
110+
%result = apply %callee_trivial(%instance) : $@convention(thin) (S) -> ()
111+
return %result : $()
112+
}
113+
94114
////////////////////////////////////////////////////////////////////////////////
95115
// begin_apply
96116
////////////////////////////////////////////////////////////////////////////////
@@ -130,6 +150,20 @@ bb2:
130150
unwind
131151
}
132152

153+
sil hidden [ossa] [always_inline] @callee_coro_trivial : $@yield_once @convention(method) (S) -> @yields @inout S {
154+
bb0(%instance : $S):
155+
%addr = alloc_stack $S
156+
store %instance to [trivial] %addr : $*S
157+
yield %addr : $*S, resume bb1, unwind bb2
158+
bb1:
159+
dealloc_stack %addr : $*S
160+
%result = tuple ()
161+
return %result : $()
162+
bb2:
163+
dealloc_stack %addr : $*S
164+
unwind
165+
}
166+
133167
// tests
134168

135169
// CHECK-LABEL: sil [ossa] @caller_owned_callee_coro_owned : $@convention(method) (@owned C) -> () {
@@ -242,6 +276,27 @@ bb0(%instance : @guaranteed $C):
242276
return %retval : $()
243277
}
244278

279+
// CHECK-LABEL: sil hidden [ossa] @caller_trivial_callee_coro_trivial : $@convention(method) (S) -> () {
280+
// CHECK: {{bb[0-9]+}}([[REGISTER_0:%[^,]+]] : $S):
281+
// CHECK: [[REGISTER_1:%[^,]+]] = alloc_stack $S
282+
// CHECK: store [[REGISTER_0]] to [trivial] [[REGISTER_1]] : $*S
283+
// CHECK: dealloc_stack [[REGISTER_1]] : $*S
284+
// CHECK: [[REGISTER_4:%[^,]+]] = tuple ()
285+
// CHECK: [[REGISTER_5:%[^,]+]] = tuple ()
286+
// CHECK: return [[REGISTER_5]] : $()
287+
// CHECK: {{bb[0-9]+}}:
288+
// CHECK: dealloc_stack [[REGISTER_1]] : $*S
289+
// CHECK: unreachable
290+
// CHECK-LABEL: } // end sil function 'caller_trivial_callee_coro_trivial'
291+
sil hidden [ossa] @caller_trivial_callee_coro_trivial : $@convention(method) (S) -> () {
292+
bb0(%instance : $S):
293+
%callee_coro_trivial = function_ref @callee_coro_trivial : $@yield_once @convention(method) (S) -> @yields @inout S
294+
(%addr, %continuation) = begin_apply %callee_coro_trivial(%instance) : $@yield_once @convention(method) (S) -> @yields @inout S
295+
end_apply %continuation
296+
%retval = tuple ()
297+
return %retval : $()
298+
}
299+
245300
////////////////////////////////////////////////////////////////////////////////
246301
// try_apply
247302
////////////////////////////////////////////////////////////////////////////////
@@ -270,6 +325,16 @@ bb2:
270325
return %18 : $()
271326
}
272327

328+
sil [ossa] @callee_error_trivial : $@convention(thin) (S) -> @error Error {
329+
bb0(%0 : $S):
330+
cond_br undef, bb1, bb2
331+
bb1:
332+
throw undef : $Error
333+
bb2:
334+
%18 = tuple ()
335+
return %18 : $()
336+
}
337+
273338
// tests
274339

275340
// CHECK-LABEL: sil [ossa] @callee_owned_callee_error_owned : $@convention(thin) (@owned C) -> @error Error {
@@ -384,3 +449,24 @@ bb1(%9 : $()):
384449
bb2(%12 : @owned $Error):
385450
throw %12 : $Error
386451
}
452+
453+
// CHECK-LABEL: sil hidden [ossa] @callee_trivial_callee_error_trivial : $@convention(thin) (S) -> @error Error {
454+
// CHECK: {{bb[^,]+}}({{%[^,]+}} : $S):
455+
// CHECK: cond_br undef, [[THROW_BLOCK:bb[^,]+]], [[REGULAR_BLOCK:bb[0-9]+]]
456+
// CHECK: [[THROW_BLOCK]]:
457+
// CHECK: throw undef
458+
// CHECK: [[REGULAR_BLOCK]]:
459+
// CHECK: [[ORIGINAL_RETVAL:%[^,]+]] = tuple ()
460+
// CHECK: [[RETVAL:%[^,]+]] = tuple ()
461+
// CHECK: return [[RETVAL]]
462+
// CHECK-LABEL: } // end sil function 'callee_trivial_callee_error_trivial'
463+
sil hidden [ossa] @callee_trivial_callee_error_trivial : $@convention(thin) (S) -> @error Error {
464+
bb0(%instance : $S):
465+
%callee_error_trivial = function_ref @callee_error_trivial : $@convention(thin) (S) -> @error Error
466+
try_apply %callee_error_trivial(%instance) : $@convention(thin) (S) -> @error Error, normal bb1, error bb2
467+
bb1(%9 : $()):
468+
%10 = tuple ()
469+
return %10 : $()
470+
bb2(%12 : @owned $Error):
471+
throw %12 : $Error
472+
}

0 commit comments

Comments
 (0)