[PATCH] D138511: [CodeGen][AArch64] Fix AArch64ABIInfo::EmitAAPCSVAArg crash with empty record type in variadic arg

Yurong via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 29 10:36:45 PST 2022


yronglin updated this revision to Diff 478633.
yronglin added a comment.

Use  AArch64ABIInfo::classifyArgumentType().isIgnore() to check empty record vaarg


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138511/new/

https://reviews.llvm.org/D138511

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/aarch64-varargs.c


Index: clang/test/CodeGen/aarch64-varargs.c
===================================================================
--- clang/test/CodeGen/aarch64-varargs.c
+++ clang/test/CodeGen/aarch64-varargs.c
@@ -894,4 +894,10 @@
 // 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*
+}
Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -5997,6 +5997,16 @@
                                        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(0) / 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138511.478633.patch
Type: text/x-patch
Size: 1648 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221129/8dac0b92/attachment.bin>


More information about the cfe-commits mailing list