Skip to content

Commit 09596bb

Browse files
committed
[X86_64] fix arg pass error in struct.
In some struct like s67, only one i64 register is used when the structure parameter is transferred, which is obviously incorrect.So we need to treat the split case specially, using memory like gcc.
1 parent 49a4ec2 commit 09596bb

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

clang/lib/CodeGen/Targets/X86.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2100,8 +2100,12 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo,
21002100
postMerge(Size, Lo, Hi);
21012101
return;
21022102
}
2103+
2104+
bool InMemory = Offset % getContext().getTypeAlign(i->getType()) ||
2105+
(i->getType()->getAs<BuiltinType>() &&
2106+
Offset % getContext().getTypeSize(i->getType()));
21032107
// Note, skip this test for bit-fields, see below.
2104-
if (!BitField && Offset % getContext().getTypeAlign(i->getType())) {
2108+
if (!BitField && InMemory) {
21052109
Lo = Memory;
21062110
postMerge(Size, Lo, Hi);
21072111
return;

clang/test/CodeGen/X86/x86_64-arguments.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,24 @@ typedef float t66 __attribute__((__vector_size__(128), __aligned__(128)));
533533
void f66(t66 a0) {
534534
}
535535

536+
typedef long long t67 __attribute__((aligned (4)));
537+
struct s67 {
538+
int a;
539+
t67 b;
540+
};
541+
// CHECK-LABEL: define{{.*}} void @f67(ptr noundef byval(%struct.s67) align 8 %x)
542+
void f67(struct s67 x) {
543+
}
544+
545+
typedef double t68 __attribute__((aligned (4)));
546+
struct s68 {
547+
int a;
548+
t68 b;
549+
};
550+
// CHECK-LABEL: define{{.*}} void @f68(ptr noundef byval(%struct.s68) align 8 %x)
551+
void f68(struct s68 x) {
552+
}
553+
536554
/// The synthesized __va_list_tag does not have file/line fields.
537555
// CHECK: = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "__va_list_tag",
538556
// CHECK-NOT: file:

0 commit comments

Comments
 (0)