Skip to content

EscapeUtils: fix a wrong handling of argument indices in walkUpApplyResult #62828

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,10 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
switch effect.kind {
case .escapingToReturn(let toPath, let exclusive):
if exclusive && path.projectionPath.matches(pattern: toPath) {
let arg = apply.arguments[effect.argumentIndex]
guard let callerArgIdx = apply.callerArgIndex(calleeArgIndex: effect.argumentIndex) else {
return .abortWalk
}
let arg = apply.arguments[callerArgIdx]

let p = Path(projectionPath: effect.pathPattern, followStores: path.followStores, knownType: nil)
if walkUp(addressOrValue: arg, path: p) == .abortWalk {
Expand Down
24 changes: 24 additions & 0 deletions test/SILOptimizer/escape_info.sil
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,10 @@ sil [ossa] @closure5 : $@convention(thin) (@guaranteed Y, @guaranteed X) -> () {
[%1: escape => %0, noescape]
}

sil [ossa] @closure6 : $@convention(thin) (@guaranteed Y, @guaranteed Y) -> @owned Y {
[%1: escape c*.v** => %r.c*.v**]
}

// CHECK-LABEL: Escape information for callClosure1:
// CHECK: - : %0 = alloc_ref $Y
// CHECK: global: %1 = alloc_ref $Y
Expand Down Expand Up @@ -1319,3 +1323,23 @@ sil @test_debug_value : $@convention(thin) () -> () {
%11 = tuple ()
return %11 : $()
}

// CHECK-LABEL: Escape information for test_walk_up_partial_apply_argument:
// CHECK: global: %0 = alloc_ref $Y // users: %3, %2
// CHECK: global: %6 = alloc_ref $X // user: %7
// CHECK: End function test_walk_up_partial_apply_argument
sil @test_walk_up_partial_apply_argument : $@convention(thin) () -> () {
bb0:
%0 = alloc_ref $Y
%2 = function_ref @closure6 : $@convention(thin) (@guaranteed Y, @guaranteed Y) -> @owned Y
%3 = partial_apply [callee_guaranteed] %2(%0) : $@convention(thin) (@guaranteed Y, @guaranteed Y) -> @owned Y
%8 = apply %3(%0) : $@callee_guaranteed (@guaranteed Y) -> @owned Y
%9 = ref_element_addr %8 : $Y, #Y.s
%10 = struct_element_addr %9 : $*Str, #Str.a

%11 = alloc_ref $X
store %11 to %10 : $*X
%13 = tuple ()
return %13 : $()
}