Skip to content

Commit 7ad4ce8

Browse files
authored
Merge pull request #21190 from aschwaighofer/irgen_fix_partial_apply_indirect_struct_of_class-5.0
[5.0] IRGen: Fix building a closure that captures a struct containing…
2 parents e231ae1 + 01a5351 commit 7ad4ce8

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,9 @@ void irgen::emitFunctionPartialApplication(
14341434
llvm::Value *ctx = args.claimNext();
14351435
if (isIndirectFormalParameter(*singleRefcountedConvention))
14361436
ctx = IGF.Builder.CreateLoad(ctx, IGF.IGM.getPointerAlignment());
1437-
ctx = IGF.Builder.CreateBitCast(ctx, IGF.IGM.RefCountedPtrTy);
1437+
// We might get a struct containing a pointer e.g type <{ %AClass* }>
1438+
if (ctx->getType() != IGF.IGM.RefCountedPtrTy)
1439+
ctx = IGF.coerceValue(ctx, IGF.IGM.RefCountedPtrTy, IGF.IGM.DataLayout);
14381440
out.add(ctx);
14391441
return;
14401442
}

test/IRGen/partial_apply.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,3 +528,28 @@ bb2(%r : $()):
528528
bb3(%v : $()):
529529
return %v : $()
530530
}
531+
532+
struct A1 {
533+
let b: () -> ()
534+
}
535+
536+
struct A2<T> {
537+
let a: T
538+
}
539+
540+
class A3 {}
541+
542+
sil @amethod : $@convention(method) (@in_guaranteed A2<A3>) -> (@owned A1, @error Error)
543+
544+
sil @repo : $@convention(thin) (@in_guaranteed A2<A3>) -> @owned @callee_guaranteed () -> (@owned A1, @error Error) {
545+
bb0(%0 : $*A2<A3>):
546+
%1 = load %0 : $*A2<A3>
547+
%2 = alloc_stack $A2<A3>
548+
store %1 to %2 : $*A2<A3>
549+
%4 = function_ref @amethod : $@convention(method) (@in_guaranteed A2<A3>) -> (@owned A1, @error Error)
550+
%5 = partial_apply [callee_guaranteed] %4(%2) : $@convention(method) (@in_guaranteed A2<A3>) -> (@owned A1, @error Error)
551+
dealloc_stack %2 : $*A2<A3>
552+
return %5 : $@callee_guaranteed () -> (@owned A1, @error Error)
553+
}
554+
555+
sil_vtable A3 {}

0 commit comments

Comments
 (0)