Skip to content

[5.0] IRGen: Fix building a closure that captures a struct containing… #21190

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
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
4 changes: 3 additions & 1 deletion lib/IRGen/GenFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,9 @@ void irgen::emitFunctionPartialApplication(
llvm::Value *ctx = args.claimNext();
if (isIndirectFormalParameter(*singleRefcountedConvention))
ctx = IGF.Builder.CreateLoad(ctx, IGF.IGM.getPointerAlignment());
ctx = IGF.Builder.CreateBitCast(ctx, IGF.IGM.RefCountedPtrTy);
// We might get a struct containing a pointer e.g type <{ %AClass* }>
if (ctx->getType() != IGF.IGM.RefCountedPtrTy)
ctx = IGF.coerceValue(ctx, IGF.IGM.RefCountedPtrTy, IGF.IGM.DataLayout);
out.add(ctx);
return;
}
Expand Down
25 changes: 25 additions & 0 deletions test/IRGen/partial_apply.sil
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,28 @@ bb2(%r : $()):
bb3(%v : $()):
return %v : $()
}

struct A1 {
let b: () -> ()
}

struct A2<T> {
let a: T
}

class A3 {}

sil @amethod : $@convention(method) (@in_guaranteed A2<A3>) -> (@owned A1, @error Error)

sil @repo : $@convention(thin) (@in_guaranteed A2<A3>) -> @owned @callee_guaranteed () -> (@owned A1, @error Error) {
bb0(%0 : $*A2<A3>):
%1 = load %0 : $*A2<A3>
%2 = alloc_stack $A2<A3>
store %1 to %2 : $*A2<A3>
%4 = function_ref @amethod : $@convention(method) (@in_guaranteed A2<A3>) -> (@owned A1, @error Error)
%5 = partial_apply [callee_guaranteed] %4(%2) : $@convention(method) (@in_guaranteed A2<A3>) -> (@owned A1, @error Error)
dealloc_stack %2 : $*A2<A3>
return %5 : $@callee_guaranteed () -> (@owned A1, @error Error)
}

sil_vtable A3 {}