diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp index 08f03aa45255d..0accb225122be 100644 --- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -907,13 +907,17 @@ static StructType *buildFrameType(Function &F, coro::Shape &Shape, // Create an entry for every spilled value. for (auto &S : FrameData.Spills) { Type *FieldType = S.first->getType(); + MaybeAlign MA; // For byval arguments, we need to store the pointed value in the frame, // instead of the pointer itself. - if (const Argument *A = dyn_cast(S.first)) - if (A->hasByValAttr()) + if (const Argument *A = dyn_cast(S.first)) { + if (A->hasByValAttr()) { FieldType = A->getParamByValType(); - FieldIDType Id = B.addField(FieldType, std::nullopt, false /*header*/, - true /*IsSpillOfValue*/); + MA = A->getParamAlign(); + } + } + FieldIDType Id = + B.addField(FieldType, MA, false /*header*/, true /*IsSpillOfValue*/); FrameData.setFieldIndex(S.first, Id); } diff --git a/llvm/test/Transforms/Coroutines/coro-byval-param.ll b/llvm/test/Transforms/Coroutines/coro-byval-param.ll index 38ab5ac481cd9..864b7cae9ca5e 100644 --- a/llvm/test/Transforms/Coroutines/coro-byval-param.ll +++ b/llvm/test/Transforms/Coroutines/coro-byval-param.ll @@ -56,8 +56,9 @@ coro.ret: ; preds = %coro.free, %cleanup ret ptr %call2 } -; check that the frame contains the entire struct, instead of just the struct pointer -; CHECK: %foo.Frame = type { ptr, ptr, %promise_type, %struct.A, i1 } +; check that the frame contains the entire struct, instead of just the struct pointer, +; and that the alignment is taken into account. +; CHECK: %foo.Frame = type { ptr, ptr, %promise_type, i1, [6 x i8], %struct.A } ; Function Attrs: argmemonly nounwind readonly declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1