Skip to content

5.9: [IRGen] Cast dynamic alloca to appropriate type. #66086

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 @@ -2158,7 +2158,9 @@ Optional<StackAddress> irgen::emitFunctionPartialApplication(
HeapNonFixedOffsets offsets(IGF, layout);
if (outType->isNoEscape()) {
stackAddr = IGF.emitDynamicAlloca(
IGF.IGM.Int8Ty, layout.isFixedLayout() ? layout.emitSize(IGF.IGM) : offsets.getSize() , Alignment(16));
IGF.IGM.Int8Ty,
layout.isFixedLayout() ? layout.emitSize(IGF.IGM) : offsets.getSize(),
Alignment(16));
stackAddr = stackAddr->withAddress(IGF.Builder.CreateElementBitCast(
stackAddr->getAddress(), IGF.IGM.OpaqueTy));
data = stackAddr->getAddress().getAddress();
Expand Down
13 changes: 10 additions & 3 deletions lib/IRGen/GenOpaque.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,11 @@ StackAddress IRGenFunction::emitDynamicAlloca(llvm::Type *eltTy,
// MaximumAlignment.
byteCount = alignUpToMaximumAlignment(IGM.SizeTy, byteCount);
auto address = emitTaskAlloc(byteCount, align);
return {address, address.getAddress()};
// In coroutines, call llvm.coro.alloca.alloc.
auto stackAddress = StackAddress{address, address.getAddress()};
stackAddress = stackAddress.withAddress(
Builder.CreateElementBitCast(stackAddress.getAddress(), eltTy));
return stackAddress;
// In coroutines, call llvm.coro.alloca.alloc.
} else if (isCoroutine()) {
// NOTE: llvm does not support dynamic allocas in coroutines.

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

return {Address(ptr, IGM.Int8Ty, align), allocToken};
auto stackAddress =
StackAddress{Address(ptr, IGM.Int8Ty, align), allocToken};
stackAddress = stackAddress.withAddress(
Builder.CreateElementBitCast(stackAddress.getAddress(), eltTy));
return stackAddress;
}

// Otherwise, use a dynamic alloca.
Expand Down
23 changes: 23 additions & 0 deletions validation-test/IRGen/rdar109540863.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %target-swift-frontend %s -disable-availability-checking -emit-ir | %FileCheck %s

// REQUIRES: concurrency

// CHECK: define {{.*}}@callee
@_silgen_name("callee")
func callee<each T : P>(_ ts: repeat each T) async {
(repeat (each ts).foo())
}

// CHECK: define {{.*}}@caller
@_silgen_name("caller")
func caller<each T1 : P>(t1: repeat each T1) async {
await callee(S(), repeat each t1)
}

struct S : P {
func foo() {
}
}
protocol P {
func foo()
}