Skip to content

Commit 092441e

Browse files
authored
Merge pull request #82799 from eeckstein/fix-escape-utils-6.2
[6.2] EscapeUtils: consider that a pointer argument can escape a function call
2 parents d48956c + fc7c993 commit 092441e

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
640640
}
641641

642642
// Indirect arguments cannot escape the function, but loaded values from such can.
643-
if !followLoads(at: path) {
643+
if argOp.value.type.isAddress && !followLoads(at: path) {
644644
if let beginApply = apply as? BeginApplyInst {
645645
// begin_apply can yield an address value.
646646
if !indirectResultEscapes(of: beginApply, path: path) {

test/SILOptimizer/addr_escape_info.sil

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,3 +956,21 @@ bb0(%0 : $Int):
956956
%9 = tuple ()
957957
return %9 : $()
958958
}
959+
960+
// CHECK-LABEL: Address escape information for escaping_pointer_through_function:
961+
// CHECK: value: %1 = alloc_stack $Int
962+
// CHECK-NEXT: ==> %4 = apply undef(%3) : $@convention(thin) (Builtin.RawPointer) -> UnsafeMutableRawBufferPointer
963+
// CHECK-NEXT: ==> %5 = apply undef(%4) : $@convention(thin) (UnsafeMutableRawBufferPointer) -> ()
964+
// CHECK-NEXT: End function escaping_pointer_through_function
965+
sil [ossa] @escaping_pointer_through_function : $@convention(thin) (Int) -> () {
966+
bb0(%0 : $Int):
967+
%1 = alloc_stack $Int
968+
fix_lifetime %1
969+
%3 = address_to_pointer %1 to $Builtin.RawPointer
970+
%4 = apply undef(%3) : $@convention(thin) (Builtin.RawPointer) -> UnsafeMutableRawBufferPointer
971+
%5 = apply undef(%4) : $@convention(thin) (UnsafeMutableRawBufferPointer) -> ()
972+
dealloc_stack %1
973+
%7 = tuple ()
974+
return %7
975+
}
976+

test/SILOptimizer/redundant_load_elim_ossa.sil

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,3 +1761,25 @@ bb0(%0 : $Int):
17611761
dealloc_stack %3
17621762
return %6
17631763
}
1764+
1765+
sil @forwardPtr : $@convention(thin) (Builtin.RawPointer) -> UnsafeMutableRawBufferPointer {
1766+
[global: read]
1767+
}
1768+
1769+
// CHECK-LABEL: sil [ossa] @escaping_pointer_through_function :
1770+
// CHECK: [[LD:%.*]] = load [trivial] %1
1771+
// CHECK: return [[LD]]
1772+
// CHECK-LABEL: } // end sil function 'escaping_pointer_through_function'
1773+
sil [ossa] @escaping_pointer_through_function : $@convention(thin) (Int) -> Int {
1774+
bb0(%0 : $Int):
1775+
%1 = alloc_stack $Int
1776+
store %0 to [trivial] %1
1777+
%3 = address_to_pointer %1 to $Builtin.RawPointer
1778+
%4 = function_ref @forwardPtr : $@convention(thin) (Builtin.RawPointer) -> UnsafeMutableRawBufferPointer
1779+
%5 = apply %4(%3) : $@convention(thin) (Builtin.RawPointer) -> UnsafeMutableRawBufferPointer
1780+
%6 = apply undef(%5) : $@convention(thin) (UnsafeMutableRawBufferPointer) -> ()
1781+
%7 = load [trivial] %1
1782+
dealloc_stack %1
1783+
return %7
1784+
}
1785+

0 commit comments

Comments
 (0)