Skip to content

Commit ebe530e

Browse files
committed
[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: #59034 Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D138511
1 parent 3c0c24e commit ebe530e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

clang/lib/CodeGen/TargetInfo.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5998,6 +5998,16 @@ Address AArch64ABIInfo::EmitAAPCSVAArg(Address VAListAddr, QualType Ty,
59985998
CodeGenFunction &CGF) const {
59995999
ABIArgInfo AI = classifyArgumentType(Ty, /*IsVariadic=*/true,
60006000
CGF.CurFnInfo->getCallingConvention());
6001+
// Empty records are ignored for parameter passing purposes.
6002+
if (AI.isIgnore()) {
6003+
uint64_t PointerSize = getTarget().getPointerWidth(LangAS::Default) / 8;
6004+
CharUnits SlotSize = CharUnits::fromQuantity(PointerSize);
6005+
VAListAddr = CGF.Builder.CreateElementBitCast(VAListAddr, CGF.Int8PtrTy);
6006+
auto *Load = CGF.Builder.CreateLoad(VAListAddr);
6007+
Address Addr = Address(Load, CGF.Int8Ty, SlotSize);
6008+
return CGF.Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(Ty));
6009+
}
6010+
60016011
bool IsIndirect = AI.isIndirect();
60026012

60036013
llvm::Type *BaseTy = CGF.ConvertType(Ty);

clang/test/CodeGen/aarch64-varargs.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,4 +894,10 @@ void check_start(int n, ...) {
894894
// CHECK: call void @llvm.va_start(i8* [[VOIDP_THE_LIST]])
895895
}
896896

897-
897+
typedef struct {} empty;
898+
empty empty_record_test(void) {
899+
// CHECK-LABEL: define{{.*}} void @empty_record_test()
900+
return va_arg(the_list, empty);
901+
// CHECK: [[GR_OFFS:%[a-z_0-9]+]] = load i8*, i8** getelementptr inbounds (%struct.__va_list, %struct.__va_list* @the_list, i32 0, i32 0)
902+
// CHECK: [[ADDR:%[a-z._0-9]+]] = bitcast i8* [[GR_OFFS]] to %struct.empty*
903+
}

0 commit comments

Comments
 (0)