diff --git a/lib/IRGen/GenFunc.cpp b/lib/IRGen/GenFunc.cpp index 9fa62c75fc33f..9d09b0c833c9c 100644 --- a/lib/IRGen/GenFunc.cpp +++ b/lib/IRGen/GenFunc.cpp @@ -2158,7 +2158,9 @@ Optional 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(); diff --git a/lib/IRGen/GenOpaque.cpp b/lib/IRGen/GenOpaque.cpp index d738bac6e4373..7a1f170762505 100644 --- a/lib/IRGen/GenOpaque.cpp +++ b/lib/IRGen/GenOpaque.cpp @@ -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. @@ -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. diff --git a/validation-test/IRGen/rdar109540863.swift b/validation-test/IRGen/rdar109540863.swift new file mode 100644 index 0000000000000..2cc6004bde2fc --- /dev/null +++ b/validation-test/IRGen/rdar109540863.swift @@ -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(_ ts: repeat each T) async { + (repeat (each ts).foo()) +} + +// CHECK: define {{.*}}@caller +@_silgen_name("caller") +func caller(t1: repeat each T1) async { + await callee(S(), repeat each t1) +} + +struct S : P { + func foo() { + } +} +protocol P { + func foo() +}