Skip to content

Commit 000f2b5

Browse files
authored
[X86_64] fix arg pass error in struct. (#86902)
``` typedef long long t67 __attribute__((aligned (4))); struct s67 { int a; t67 b; }; void f67(struct s67 x) { } ``` When classify: a: Lo = Integer, Hi = NoClass b: Lo = Integer, Hi = NoClass struct S: Lo = Integer, Hi = NoClass ``` define dso_local void @F67(i64 %x.coerce) { ``` In this case, 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. fix #85387.
1 parent 71097e9 commit 000f2b5

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

clang/lib/CodeGen/Targets/X86.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2106,8 +2106,11 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo,
21062106
postMerge(Size, Lo, Hi);
21072107
return;
21082108
}
2109+
2110+
bool IsInMemory =
2111+
Offset % getContext().getTypeAlign(i->getType().getCanonicalType());
21092112
// Note, skip this test for bit-fields, see below.
2110-
if (!BitField && Offset % getContext().getTypeAlign(i->getType())) {
2113+
if (!BitField && IsInMemory) {
21112114
Lo = Memory;
21122115
postMerge(Size, Lo, Hi);
21132116
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)