Skip to content

Commit 0c5fe56

Browse files
committed
Bailout on address apply result while computng argument escaping effects
1 parent 20b23d6 commit 0c5fe56

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
725725
}
726726
case .escapingToReturn(let toPath, let exclusive):
727727
if effect.matches(calleeArgIdx, argPath.projectionPath) {
728-
guard let fas = apply as? FullApplySite, let result = fas.singleDirectResult else {
728+
guard let fas = apply as? FullApplySite, let result = fas.singleDirectResult, result.type.isObject else {
729729
return isEscaping
730730
}
731731

test/SILOptimizer/escape_effects.sil

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,3 +414,42 @@ bb0(%0 : $*Wrapper):
414414
%2 = struct_element_addr %0, #Wrapper._k
415415
return %2
416416
}
417+
418+
// CHECK: sil [ossa] @call_mutate_accessor : $@convention(thin) (@inout Wrapper, @owned Klass) -> () {
419+
// CHECK-NOT: [.*]
420+
// CHECK: bb0({{.*}}):
421+
sil [ossa] @call_mutate_accessor : $@convention(thin) (@inout Wrapper, @owned Klass) -> () {
422+
bb0(%0 : $*Wrapper, %1 : @owned $Klass):
423+
%func = function_ref @mutate_accessor : $@convention(thin) (@inout Wrapper) -> @inout Klass
424+
%addr = apply %func(%0) : $@convention(thin) (@inout Wrapper) -> @inout Klass
425+
store %1 to [assign] %addr
426+
%r = tuple ()
427+
return %r
428+
}
429+
430+
sil [ossa] @modify_accessor : $@yield_once @convention(thin) (@inout Wrapper) -> @yields @inout Klass {
431+
bb0(%0 : $*Wrapper):
432+
%2 = struct_element_addr %0, #Wrapper._k
433+
yield %2, resume bb1, unwind bb2
434+
435+
bb1:
436+
%t = tuple ()
437+
return %t
438+
439+
bb2:
440+
unwind
441+
}
442+
443+
// CHECK: sil [ossa] @call_modify_accessor : $@convention(thin) (@inout Wrapper, @owned Klass) -> () {
444+
// CHECK-NOT: [.*]
445+
// CHECK: bb0({{.*}}):
446+
sil [ossa] @call_modify_accessor : $@convention(thin) (@inout Wrapper, @owned Klass) -> () {
447+
bb0(%0 : $*Wrapper, %1 : @owned $Klass):
448+
%func = function_ref @modify_accessor : $@yield_once @convention(thin) (@inout Wrapper) -> @yields @inout Klass
449+
(%addr, %tok) = begin_apply %func(%0) : $@yield_once @convention(thin) (@inout Wrapper) -> @yields @inout Klass
450+
store %1 to [assign] %addr
451+
end_apply %tok as $()
452+
%r = tuple ()
453+
return %r
454+
}
455+

0 commit comments

Comments
 (0)