Skip to content

Commit efe762d

Browse files
Merge pull request #66014 from nate-chandler/rdar109540863
[IRGen] Cast dynamic alloca to appropriate type.
2 parents dabfcb2 + 4b46622 commit efe762d

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

lib/IRGen/GenFunc.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2158,7 +2158,9 @@ Optional<StackAddress> irgen::emitFunctionPartialApplication(
21582158
HeapNonFixedOffsets offsets(IGF, layout);
21592159
if (outType->isNoEscape()) {
21602160
stackAddr = IGF.emitDynamicAlloca(
2161-
IGF.IGM.Int8Ty, layout.isFixedLayout() ? layout.emitSize(IGF.IGM) : offsets.getSize() , Alignment(16));
2161+
IGF.IGM.Int8Ty,
2162+
layout.isFixedLayout() ? layout.emitSize(IGF.IGM) : offsets.getSize(),
2163+
Alignment(16));
21622164
stackAddr = stackAddr->withAddress(IGF.Builder.CreateElementBitCast(
21632165
stackAddr->getAddress(), IGF.IGM.OpaqueTy));
21642166
data = stackAddr->getAddress().getAddress();

lib/IRGen/GenOpaque.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,11 @@ StackAddress IRGenFunction::emitDynamicAlloca(llvm::Type *eltTy,
578578
// MaximumAlignment.
579579
byteCount = alignUpToMaximumAlignment(IGM.SizeTy, byteCount);
580580
auto address = emitTaskAlloc(byteCount, align);
581-
return {address, address.getAddress()};
582-
// In coroutines, call llvm.coro.alloca.alloc.
581+
auto stackAddress = StackAddress{address, address.getAddress()};
582+
stackAddress = stackAddress.withAddress(
583+
Builder.CreateElementBitCast(stackAddress.getAddress(), eltTy));
584+
return stackAddress;
585+
// In coroutines, call llvm.coro.alloca.alloc.
583586
} else if (isCoroutine()) {
584587
// NOTE: llvm does not support dynamic allocas in coroutines.
585588

@@ -603,7 +606,11 @@ StackAddress IRGenFunction::emitDynamicAlloca(llvm::Type *eltTy,
603606
auto ptr = Builder.CreateIntrinsicCall(llvm::Intrinsic::coro_alloca_get,
604607
{allocToken});
605608

606-
return {Address(ptr, IGM.Int8Ty, align), allocToken};
609+
auto stackAddress =
610+
StackAddress{Address(ptr, IGM.Int8Ty, align), allocToken};
611+
stackAddress = stackAddress.withAddress(
612+
Builder.CreateElementBitCast(stackAddress.getAddress(), eltTy));
613+
return stackAddress;
607614
}
608615

609616
// Otherwise, use a dynamic alloca.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-frontend %s -disable-availability-checking -emit-ir | %FileCheck %s
2+
3+
// REQUIRES: concurrency
4+
5+
// CHECK: define {{.*}}@callee
6+
@_silgen_name("callee")
7+
func callee<each T : P>(_ ts: repeat each T) async {
8+
(repeat (each ts).foo())
9+
}
10+
11+
// CHECK: define {{.*}}@caller
12+
@_silgen_name("caller")
13+
func caller<each T1 : P>(t1: repeat each T1) async {
14+
await callee(S(), repeat each t1)
15+
}
16+
17+
struct S : P {
18+
func foo() {
19+
}
20+
}
21+
protocol P {
22+
func foo()
23+
}

0 commit comments

Comments
 (0)