https://github.com/hstk30-hw updated https://github.com/llvm/llvm-project/pull/72197
>From 18c2151e870b757fe3238cc4031597352ecc440e Mon Sep 17 00:00:00 2001 From: hstk30-hw <hanwe...@huawei.com> Date: Sat, 18 Nov 2023 11:00:29 +0000 Subject: [PATCH] fix: empty record size > 64 with align let va_list get out of sync --- clang/lib/CodeGen/Targets/AArch64.cpp | 11 ++++++++--- clang/test/CodeGen/aarch64-args.cpp | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp b/clang/lib/CodeGen/Targets/AArch64.cpp index be5145daa00b7f5..46583e7c570a5d9 100644 --- a/clang/lib/CodeGen/Targets/AArch64.cpp +++ b/clang/lib/CodeGen/Targets/AArch64.cpp @@ -295,8 +295,12 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool IsVariadic, CGCXXABI::RAA_DirectInMemory); } - // Empty records are always ignored on Darwin, but actually passed in C++ mode - // elsewhere for GNU compatibility. + // AAPCS64 does not say that empty records are ignored as arguments, + // but other compilers do so in certain situations, and we copy that behavior. + // Those situations are in fact language-mode-specific, which seems really + // unfortunate, but it's something we just have to accept. If this doesn't + // apply, just fall through to the standard argument-handling path. + // Darwin overrides the psABI here to ignore all empty records in all modes. uint64_t Size = getContext().getTypeSize(Ty); bool IsEmpty = isEmptyRecord(getContext(), Ty, true); if (IsEmpty || Size == 0) { @@ -307,7 +311,8 @@ AArch64ABIInfo::classifyArgumentType(QualType Ty, bool IsVariadic, // 0. if (IsEmpty && Size == 0) return ABIArgInfo::getIgnore(); - return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext())); + if (Size <= 64) + return ABIArgInfo::getDirect(llvm::Type::getInt8Ty(getVMContext())); } // Homogeneous Floating-point Aggregates (HFAs) need to be expanded. diff --git a/clang/test/CodeGen/aarch64-args.cpp b/clang/test/CodeGen/aarch64-args.cpp index fe1298cc683a404..1fc1b89785fee81 100644 --- a/clang/test/CodeGen/aarch64-args.cpp +++ b/clang/test/CodeGen/aarch64-args.cpp @@ -65,3 +65,22 @@ EXTERNC struct SortOfEmpty sort_of_empty_ret(void) { struct SortOfEmpty e; return e; } + +// CHECK-GNU-CXX: define{{.*}} i32 @empty_align8_arg(i8 %a.coerce, i32 noundef %b) +struct EmptyAlign8 { int __attribute__((aligned(8))) : 0; }; +EXTERNC int empty_align8_arg(struct EmptyAlign8 a, int b) { + return b; +} + +// CHECK-GNU-CXX: define{{.*}} i32 @empty_align16_arg(i128 %a.coerce, i32 noundef %b) +struct EmptyAlign16 { long long int __attribute__((aligned(16))) : 0; }; +EXTERNC int empty_align16_arg(struct EmptyAlign16 a, int b) { + return b; +} + +// CHECK-GNU-CXX: define{{.*}} i32 @empty_align32_arg(ptr noundef %a, i32 noundef %b) +struct EmptyAlign32 { long long int __attribute__((aligned(32))) : 0; }; +EXTERNC int empty_align32_arg(struct EmptyAlign32 a, int b) { + return b; +} + _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits