Skip to content

Commit a5c81b9

Browse files
authored
Merge pull request #62828 from eeckstein/fix-escape-utils
EscapeUtils: fix a wrong handling of argument indices in walkUpApplyResult
2 parents ce4ec08 + 3d86732 commit a5c81b9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,10 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
810810
switch effect.kind {
811811
case .escapingToReturn(let toPath, let exclusive):
812812
if exclusive && path.projectionPath.matches(pattern: toPath) {
813-
let arg = apply.arguments[effect.argumentIndex]
813+
guard let callerArgIdx = apply.callerArgIndex(calleeArgIndex: effect.argumentIndex) else {
814+
return .abortWalk
815+
}
816+
let arg = apply.arguments[callerArgIdx]
814817

815818
let p = Path(projectionPath: effect.pathPattern, followStores: path.followStores, knownType: nil)
816819
if walkUp(addressOrValue: arg, path: p) == .abortWalk {

test/SILOptimizer/escape_info.sil

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,10 @@ sil [ossa] @closure5 : $@convention(thin) (@guaranteed Y, @guaranteed X) -> () {
10111011
[%1: escape => %0, noescape]
10121012
}
10131013

1014+
sil [ossa] @closure6 : $@convention(thin) (@guaranteed Y, @guaranteed Y) -> @owned Y {
1015+
[%1: escape c*.v** => %r.c*.v**]
1016+
}
1017+
10141018
// CHECK-LABEL: Escape information for callClosure1:
10151019
// CHECK: - : %0 = alloc_ref $Y
10161020
// CHECK: global: %1 = alloc_ref $Y
@@ -1319,3 +1323,23 @@ sil @test_debug_value : $@convention(thin) () -> () {
13191323
%11 = tuple ()
13201324
return %11 : $()
13211325
}
1326+
1327+
// CHECK-LABEL: Escape information for test_walk_up_partial_apply_argument:
1328+
// CHECK: global: %0 = alloc_ref $Y // users: %3, %2
1329+
// CHECK: global: %6 = alloc_ref $X // user: %7
1330+
// CHECK: End function test_walk_up_partial_apply_argument
1331+
sil @test_walk_up_partial_apply_argument : $@convention(thin) () -> () {
1332+
bb0:
1333+
%0 = alloc_ref $Y
1334+
%2 = function_ref @closure6 : $@convention(thin) (@guaranteed Y, @guaranteed Y) -> @owned Y
1335+
%3 = partial_apply [callee_guaranteed] %2(%0) : $@convention(thin) (@guaranteed Y, @guaranteed Y) -> @owned Y
1336+
%8 = apply %3(%0) : $@callee_guaranteed (@guaranteed Y) -> @owned Y
1337+
%9 = ref_element_addr %8 : $Y, #Y.s
1338+
%10 = struct_element_addr %9 : $*Str, #Str.a
1339+
1340+
%11 = alloc_ref $X
1341+
store %11 to %10 : $*X
1342+
%13 = tuple ()
1343+
return %13 : $()
1344+
}
1345+

0 commit comments

Comments
 (0)