Skip to content

Commit 4b66e97

Browse files
committed
[GenPack] Cast dynamic alloca to appropriate type.
If it's allocated in an async function or a coroutine, the element type is i8. Cast the element type to metadata or wtable if its not that type already. rdar://109540863
1 parent 3865b5d commit 4b66e97

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/IRGen/GenPack.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,8 @@ irgen::emitTypeMetadataPack(IRGenFunction &IGF,
454454
auto pack = IGF.emitDynamicAlloca(IGF.IGM.TypeMetadataPtrTy, shape,
455455
IGF.IGM.getPointerAlignment(),
456456
/*allowTaskAlloc=*/true);
457+
pack = pack.withAddress(IGF.Builder.CreateElementBitCast(
458+
pack.getAddress(), IGF.IGM.TypeMetadataPtrTy));
457459

458460
auto visitFn =
459461
[&](CanType eltTy, unsigned staticIndex,
@@ -582,6 +584,8 @@ StackAddress irgen::emitWitnessTablePack(IRGenFunction &IGF,
582584
auto pack = IGF.emitDynamicAlloca(IGF.IGM.WitnessTablePtrTy, shape,
583585
IGF.IGM.getPointerAlignment(),
584586
/*allowTaskAlloc=*/true);
587+
pack = pack.withAddress(IGF.Builder.CreateElementBitCast(
588+
pack.getAddress(), IGF.IGM.WitnessTablePtrTy));
585589

586590
auto index = 0;
587591
auto visitFn = [&](CanType eltTy, unsigned staticIndex,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-swift-frontend %s -emit-ir | %FileCheck %s
2+
3+
// CHECK: define {{.*}}@callee
4+
@_silgen_name("callee")
5+
func callee<each T : P>(_ ts: repeat each T) async {
6+
(repeat (each ts).foo())
7+
}
8+
9+
// CHECK: define {{.*}}@caller
10+
@_silgen_name("caller")
11+
func caller<each T1 : P>(t1: repeat each T1) async {
12+
await callee(S(), repeat each t1)
13+
}
14+
15+
struct S : P {
16+
func foo() {
17+
}
18+
}
19+
protocol P {
20+
func foo()
21+
}

0 commit comments

Comments
 (0)