Author: yronglin Date: 2022-12-20T22:06:01+08:00 New Revision: ebe530ef7a49988a531a8928eac3ce0925f1c199
URL: https://github.com/llvm/llvm-project/commit/ebe530ef7a49988a531a8928eac3ce0925f1c199 DIFF: https://github.com/llvm/llvm-project/commit/ebe530ef7a49988a531a8928eac3ce0925f1c199.diff LOG: [CodeGen][AArch64] Fix AArch64ABIInfo::EmitAAPCSVAArg crash with empty record type in variadic arg Fix AArch64ABIInfo::EmitAAPCSVAArg crash with empty record type in variadic arg Open issue: https://github.com/llvm/llvm-project/issues/59034 Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D138511 Added: Modified: clang/lib/CodeGen/TargetInfo.cpp clang/test/CodeGen/aarch64-varargs.c Removed: ################################################################################ diff --git a/clang/lib/CodeGen/TargetInfo.cpp b/clang/lib/CodeGen/TargetInfo.cpp index bcb0e7b08574..98b54dfb1651 100644 --- a/clang/lib/CodeGen/TargetInfo.cpp +++ b/clang/lib/CodeGen/TargetInfo.cpp @@ -5998,6 +5998,16 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(Address VAListAddr, QualType Ty, CodeGenFunction &CGF) const { ABIArgInfo AI = classifyArgumentType(Ty, /*IsVariadic=*/true, CGF.CurFnInfo->getCallingConvention()); + // Empty records are ignored for parameter passing purposes. + if (AI.isIgnore()) { + uint64_t PointerSize = getTarget().getPointerWidth(LangAS::Default) / 8; + CharUnits SlotSize = CharUnits::fromQuantity(PointerSize); + VAListAddr = CGF.Builder.CreateElementBitCast(VAListAddr, CGF.Int8PtrTy); + auto *Load = CGF.Builder.CreateLoad(VAListAddr); + Address Addr = Address(Load, CGF.Int8Ty, SlotSize); + return CGF.Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(Ty)); + } + bool IsIndirect = AI.isIndirect(); llvm::Type *BaseTy = CGF.ConvertType(Ty); diff --git a/clang/test/CodeGen/aarch64-varargs.c b/clang/test/CodeGen/aarch64-varargs.c index ad457750c1e0..e4f54039dff3 100644 --- a/clang/test/CodeGen/aarch64-varargs.c +++ b/clang/test/CodeGen/aarch64-varargs.c @@ -894,4 +894,10 @@ void check_start(int n, ...) { // CHECK: call void @llvm.va_start(i8* [[VOIDP_THE_LIST]]) } - +typedef struct {} empty; +empty empty_record_test(void) { +// CHECK-LABEL: define{{.*}} void @empty_record_test() + return va_arg(the_list, empty); +// CHECK: [[GR_OFFS:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list, %struct.__va_list* @the_list, i32 0, i32 0) +// CHECK: [[ADDR:%[a-z._0-9]+]] = bitcast i8* [[GR_OFFS]] to %struct.empty* +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits