Skip to content

Commit 90ab382

Browse files
committed
[SILInliner] Removed lexical borrows of addrs.
In 79bc4cb, when -enable-experimental-lexical-lifetimes was passed, all non-trivial types were given borrow scopes. That is incorrect because address types should not receive borrow scopes. Here, that is fixed by only introducing lexical borrow scopes for arguments whose types is not an address type.
1 parent b58c41a commit 90ab382

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ SILInlineCloner::cloneInline(ArrayRef<SILValue> AppliedArgs) {
437437
unsigned idx = p.index();
438438
if (idx >= calleeConv.getSILArgIndexOfFirstParam()) {
439439
if (Apply.getFunction()->hasOwnership() && enableLexicalLifetimes) {
440-
if (!callArg->getType().isTrivial(*Apply.getFunction())) {
440+
if (!callArg->getType().isTrivial(*Apply.getFunction()) &&
441+
!callArg->getType().isAddress()) {
441442
SILBuilderWithScope builder(Apply.getInstruction(), getBuilder());
442443
if (calleeConv.getParamInfoForSILArg(idx).isGuaranteed()) {
443444
callArg = builder.createBeginBorrow(Apply.getLoc(), callArg,

test/SILOptimizer/inline_lifetime.sil

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ entry(%instance : $S):
3131
return %retval : $()
3232
}
3333

34+
sil [ossa] [always_inline] @callee_address : $@convention(thin) (@in S) -> () {
35+
entry(%instance : $*S):
36+
%retval = tuple ()
37+
return %retval : $()
38+
}
39+
3440
// tests
3541

3642
// CHECK-LABEL: sil [ossa] @caller_owned_callee_owned : $@convention(thin) (@owned C) -> () {
@@ -111,6 +117,18 @@ entry(%instance : $S):
111117
return %result : $()
112118
}
113119

120+
// CHECK-LABEL: sil [ossa] @caller_address_callee_address : $@convention(thin) (@in S) -> () {
121+
// CHECK: {{bb[^,]+}}({{%[^,]+}} : $*S):
122+
// CHECK: [[RETVAL:%[^,]+]] = tuple ()
123+
// CHECK: return [[RETVAL]]
124+
// CHECK-LABEL: } // end sil function 'caller_address_callee_address'
125+
sil [ossa] @caller_address_callee_address : $@convention(thin) (@in S) -> () {
126+
entry(%instance : $*S):
127+
%callee_address = function_ref @callee_address : $@convention(thin) (@in S) -> ()
128+
%result = apply %callee_address(%instance) : $@convention(thin) (@in S) -> ()
129+
return %result : $()
130+
}
131+
114132
////////////////////////////////////////////////////////////////////////////////
115133
// begin_apply
116134
////////////////////////////////////////////////////////////////////////////////
@@ -164,6 +182,16 @@ bb2:
164182
unwind
165183
}
166184

185+
sil hidden [ossa] [always_inline] @callee_coro_address : $@yield_once @convention(method) (@in S) -> @yields @inout S {
186+
bb0(%instance : $*S):
187+
yield %instance : $*S, resume bb1, unwind bb2
188+
bb1:
189+
%result = tuple ()
190+
return %result : $()
191+
bb2:
192+
unwind
193+
}
194+
167195
// tests
168196

169197
// CHECK-LABEL: sil [ossa] @caller_owned_callee_coro_owned : $@convention(method) (@owned C) -> () {
@@ -297,6 +325,23 @@ bb0(%instance : $S):
297325
return %retval : $()
298326
}
299327

328+
// CHECK-LABEL: sil hidden [ossa] @caller_address_callee_coro_address : $@convention(method) (@in S) -> () {
329+
// CHECK: {{bb[^,]+}}({{%[^,]+}} : $*S):
330+
// CHECK: {{%[^,]+}} = tuple ()
331+
// CHECK: [[RETVAL:%[^,]+]] = tuple ()
332+
// CHECK: return [[RETVAL]]
333+
// CHECK: {{bb[^,]+}}:
334+
// CHECK: unreachable
335+
// CHECK-LABEL: } // end sil function 'caller_address_callee_coro_address'
336+
sil hidden [ossa] @caller_address_callee_coro_address : $@convention(method) (@in S) -> () {
337+
bb0(%instance : $*S):
338+
%callee_coro_address = function_ref @callee_coro_address : $@yield_once @convention(method) (@in S) -> @yields @inout S
339+
(%addr, %continuation) = begin_apply %callee_coro_address(%instance) : $@yield_once @convention(method) (@in S) -> @yields @inout S
340+
end_apply %continuation
341+
%retval = tuple ()
342+
return %retval : $()
343+
}
344+
300345
////////////////////////////////////////////////////////////////////////////////
301346
// try_apply
302347
////////////////////////////////////////////////////////////////////////////////
@@ -335,6 +380,16 @@ bb2:
335380
return %18 : $()
336381
}
337382

383+
sil [ossa] @callee_error_address : $@convention(thin) (@in S) -> @error Error {
384+
bb0(%0 : $*S):
385+
cond_br undef, bb1, bb2
386+
bb1:
387+
throw undef : $Error
388+
bb2:
389+
%18 = tuple ()
390+
return %18 : $()
391+
}
392+
338393
// tests
339394

340395
// CHECK-LABEL: sil [ossa] @callee_owned_callee_error_owned : $@convention(thin) (@owned C) -> @error Error {
@@ -470,3 +525,24 @@ bb1(%9 : $()):
470525
bb2(%12 : @owned $Error):
471526
throw %12 : $Error
472527
}
528+
529+
// CHECK-LABEL: sil hidden [ossa] @callee_address_callee_error_address : $@convention(thin) (@in S) -> @error Error {
530+
// CHECK: {{bb[^,]+}}({{%[^,]+}} : $*S):
531+
// CHECK: cond_br undef, [[THROW_BLOCK:bb[0-9]+]], [[REGULAR_BLOCK:bb[0-9]+]]
532+
// CHECK: [[THROW_BLOCK]]:
533+
// CHECK: throw undef
534+
// CHECK: [[REGULAR_BLOCK]]:
535+
// CHECK: {{%[^,]+}} = tuple ()
536+
// CHECK: [[RETVAL:%[^,]+]] = tuple ()
537+
// CHECK: return [[RETVAL]]
538+
// CHECK-LABEL: } // end sil function 'callee_address_callee_error_address'
539+
sil hidden [ossa] @callee_address_callee_error_address : $@convention(thin) (@in S) -> @error Error {
540+
bb0(%instance : $*S):
541+
%callee_error_address = function_ref @callee_error_address : $@convention(thin) (@in S) -> @error Error
542+
try_apply %callee_error_address(%instance) : $@convention(thin) (@in S) -> @error Error, normal bb1, error bb2
543+
bb1(%9 : $()):
544+
%10 = tuple ()
545+
return %10 : $()
546+
bb2(%12 : @owned $Error):
547+
throw %12 : $Error
548+
}

0 commit comments

Comments
 (0)