[llvm] cc6b81c - [Coroutines] Take byval param alignment into account when spilling to frame (#159765)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 21 23:52:42 PDT 2025
Author: Hans Wennborg
Date: 2025-09-22T08:52:38+02:00
New Revision: cc6b81c0c0ff4692e12f08ed6ed7a39cfe813488
URL: https://github.com/llvm/llvm-project/commit/cc6b81c0c0ff4692e12f08ed6ed7a39cfe813488
DIFF: https://github.com/llvm/llvm-project/commit/cc6b81c0c0ff4692e12f08ed6ed7a39cfe813488.diff
LOG: [Coroutines] Take byval param alignment into account when spilling to frame (#159765)
Fixes #159571
Added:
Modified:
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
llvm/test/Transforms/Coroutines/coro-byval-param.ll
Removed:
################################################################################
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<Argument>(S.first))
- if (A->hasByValAttr())
+ if (const Argument *A = dyn_cast<Argument>(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
More information about the llvm-commits
mailing list