https://github.com/CoTinker created https://github.com/llvm/llvm-project/pull/86388
struct SuperEmpty { struct{ int a[0];} b;}; Such 0 sized structs in c++ mode can not be ignored in i386 for that c++ fields are never empty.But when EmitVAArg, its size is 0, so that va_list not increase.Maybe we can use direct in this case. https://github.com/llvm/llvm-project/blob/691b97c884a15a7eac641ddf67c9f2f30fb4e747/clang/lib/CodeGen/ABIInfoImpl.cpp#L202-L216 This case use indirect before and `DirectSize == 0`, now we use direct and `DirectSize == 4`. Or we can just Ignore this kind of arguments, like X86_64 did. >From dda9d5ac87b05c71079b6ed3b5d4188ff22ce356 Mon Sep 17 00:00:00 2001 From: Longsheng Mou <moulongsh...@huawei.com> Date: Sat, 23 Mar 2024 17:53:58 +0800 Subject: [PATCH] [X86_32] fix weird edge case in vaarg. struct SuperEmpty { struct{ int a[0];} b;}; Such 0 sized structs in c++ mode can not be ignored in i386 for that c++ fields are never empty.But when EmitVAArg, its size is 0, so that va_list not increase.Maybe we can use direct in this case. --- clang/lib/CodeGen/Targets/X86.cpp | 3 +++ clang/test/CodeGenCXX/regparm.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp index 1ec0f159ebcb8a..8e6e7c17452048 100644 --- a/clang/lib/CodeGen/Targets/X86.cpp +++ b/clang/lib/CodeGen/Targets/X86.cpp @@ -805,6 +805,9 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty, CCState &State, if (!IsWin32StructABI && isEmptyRecord(getContext(), Ty, true)) return ABIArgInfo::getIgnore(); + if (TI.Width == 0 && getContext().getLangOpts().CPlusPlus) + return ABIArgInfo::getDirect(); + llvm::LLVMContext &LLVMContext = getVMContext(); llvm::IntegerType *Int32 = llvm::Type::getInt32Ty(LLVMContext); bool NeedsPadding = false; diff --git a/clang/test/CodeGenCXX/regparm.cpp b/clang/test/CodeGenCXX/regparm.cpp index 1fd471c2d0727b..559702a84c99e1 100644 --- a/clang/test/CodeGenCXX/regparm.cpp +++ b/clang/test/CodeGenCXX/regparm.cpp @@ -32,7 +32,7 @@ struct S3 { } a; }; __attribute((regparm(2))) void foo4(S3 a, int b); -// CHECK: declare void @_Z4foo42S3i(ptr noundef byval(%struct.S3) align 4, i32 inreg noundef) +// CHECK: declare void @_Z4foo42S3i(%struct.anon, i32 inreg noundef) void bar3(S3 a, int b) { foo4(a, b); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits