Skip to content

Commit cc6b81c

Browse files
authored
[Coroutines] Take byval param alignment into account when spilling to frame (#159765)
Fixes #159571
1 parent 383bd69 commit cc6b81c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -907,13 +907,17 @@ static StructType *buildFrameType(Function &F, coro::Shape &Shape,
907907
// Create an entry for every spilled value.
908908
for (auto &S : FrameData.Spills) {
909909
Type *FieldType = S.first->getType();
910+
MaybeAlign MA;
910911
// For byval arguments, we need to store the pointed value in the frame,
911912
// instead of the pointer itself.
912-
if (const Argument *A = dyn_cast<Argument>(S.first))
913-
if (A->hasByValAttr())
913+
if (const Argument *A = dyn_cast<Argument>(S.first)) {
914+
if (A->hasByValAttr()) {
914915
FieldType = A->getParamByValType();
915-
FieldIDType Id = B.addField(FieldType, std::nullopt, false /*header*/,
916-
true /*IsSpillOfValue*/);
916+
MA = A->getParamAlign();
917+
}
918+
}
919+
FieldIDType Id =
920+
B.addField(FieldType, MA, false /*header*/, true /*IsSpillOfValue*/);
917921
FrameData.setFieldIndex(S.first, Id);
918922
}
919923

llvm/test/Transforms/Coroutines/coro-byval-param.ll

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ coro.ret: ; preds = %coro.free, %cleanup
5656
ret ptr %call2
5757
}
5858

59-
; check that the frame contains the entire struct, instead of just the struct pointer
60-
; CHECK: %foo.Frame = type { ptr, ptr, %promise_type, %struct.A, i1 }
59+
; check that the frame contains the entire struct, instead of just the struct pointer,
60+
; and that the alignment is taken into account.
61+
; CHECK: %foo.Frame = type { ptr, ptr, %promise_type, i1, [6 x i8], %struct.A }
6162

6263
; Function Attrs: argmemonly nounwind readonly
6364
declare token @llvm.coro.id(i32, ptr readnone, ptr nocapture readonly, ptr) #1

0 commit comments

Comments
 (0)