Skip to content

Commit 4c356e1

Browse files
committed
fix: C++ empty record with align break aarch64 AAPCS64
1 parent 4f80c06 commit 4c356e1

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

clang/lib/CodeGen/Targets/AArch64.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,12 @@ ABIArgInfo AArch64ABIInfo::classifyArgumentType(QualType Ty, bool IsVariadicFn,
422422
}
423423

424424
// Empty records:
425+
// AAPCS64 does not say that empty records are ignored as arguments,
426+
// but other compilers do so in certain situations, and we copy that behavior.
427+
// Those situations are in fact language-mode-specific, which seems really
428+
// unfortunate, but it's something we just have to accept. If this doesn't
429+
// apply, just fall through to the standard argument-handling path.
430+
// Darwin overrides the psABI here to ignore all empty records in all modes.
425431
uint64_t Size = getContext().getTypeSize(Ty);
426432
bool IsEmpty = isEmptyRecord(getContext(), Ty, true);
427433
if (!Ty->isSVESizelessBuiltinType() && (IsEmpty || Size == 0)) {
@@ -434,9 +440,6 @@ ABIArgInfo AArch64ABIInfo::classifyArgumentType(QualType Ty, bool IsVariadicFn,
434440
// behaviour here.
435441
if (Size == 0)
436442
return ABIArgInfo::getIgnore();
437-
438-
// Otherwise, they are passed as if they have a size of 1 byte.
439-
return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext()));
440443
}
441444

442445
// Homogeneous Floating-point Aggregates (HFAs) need to be expanded.

clang/test/CodeGen/AArch64/args.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct Empty {};
1717

1818
// DARWIN: define{{.*}} i32 @empty_arg(i32 noundef %a)
1919
// C: define{{.*}} i32 @empty_arg(i32 noundef %a)
20-
// CXX: define{{.*}} i32 @empty_arg(i8 %e.coerce, i32 noundef %a)
20+
// CXX: define{{.*}} i32 @empty_arg(i64 %e.coerce, i32 noundef %a)
2121
EXTERNC int empty_arg(struct Empty e, int a) {
2222
return a;
2323
}

clang/test/CodeGen/arm64-microsoft-arguments.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ S4 f4() {
5757

5858
// Pass and return from instance method called from instance method.
5959
// CHECK: define {{.*}} void @{{.*}}bar@Q1{{.*}}(ptr {{[^,]*}} %this, ptr dead_on_unwind inreg noalias writable sret(%class.P1) align 1 %agg.result)
60-
// CHECK: call void {{.*}}foo@P1{{.*}}(ptr noundef{{[^,]*}} %ref.tmp, ptr dead_on_unwind inreg writable sret(%class.P1) align 1 %agg.result, i8 %0)
60+
// CHECK: call void {{.*}}foo@P1{{.*}}(ptr noundef{{[^,]*}} %ref.tmp, ptr dead_on_unwind inreg writable sret(%class.P1) align 1 %agg.result, i64 %0)
6161

6262
class P1 {
6363
public:
@@ -76,7 +76,7 @@ P1 Q1::bar() {
7676

7777
// Pass and return from instance method called from free function.
7878
// CHECK: define {{.*}} void {{.*}}bar{{.*}}()
79-
// CHECK: call void {{.*}}foo@P2{{.*}}(ptr noundef{{[^,]*}} %ref.tmp, ptr dead_on_unwind inreg writable sret(%class.P2) align 1 %retval, i8 %0)
79+
// CHECK: call void {{.*}}foo@P2{{.*}}(ptr noundef{{[^,]*}} %ref.tmp, ptr dead_on_unwind inreg writable sret(%class.P2) align 1 %retval, i64 %0)
8080
class P2 {
8181
public:
8282
P2 foo(P2 x);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang_cc1 -triple arm64-none-linux -emit-llvm -w -o - %s | FileCheck -check-prefix=PCS %s
22

3-
// PCS: define{{.*}} void @{{.*}}(i8 %a
3+
// PCS: define{{.*}} void @{{.*}}(i64 %a.coerce)
44
struct s0 {};
55
void f0(s0 a) {}

clang/test/CodeGenCXX/arm64-darwinpcs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void test_extensions(bool a, char b, short c) {}
77

88
struct Empty {};
99
void test_empty(Empty e) {}
10-
// CHECK: define{{.*}} void @_Z10test_empty5Empty(i8
10+
// CHECK: define{{.*}} void @_Z10test_empty5Empty(i64 %e.coerce)
1111
// CHECK-DARWIN: define{{.*}} void @_Z10test_empty5Empty()
1212

1313
struct HFA {

0 commit comments

Comments
 (0)