[PATCH] D103452: [clang] Fix reading long doubles with va_arg on x86_64 mingw

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 3 02:09:35 PDT 2021


mstorsjo updated this revision to Diff 349491.
mstorsjo added a comment.

Updated to not require the types to be either `isAggregateTypeForABI(Ty)` or `Ty->isMemberPointerType()`, just check the size of the type, added a testcase for `__int128` (which I tested against GCC).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103452

Files:
  clang/lib/CodeGen/TargetInfo.cpp
  clang/test/CodeGen/mingw-long-double.c
  clang/test/CodeGen/win64-i128.c


Index: clang/test/CodeGen/win64-i128.c
===================================================================
--- clang/test/CodeGen/win64-i128.c
+++ clang/test/CodeGen/win64-i128.c
@@ -14,3 +14,14 @@
 
 // GNU64: define dso_local <2 x i64> @bar(i128* %0, i128* %1)
 // MSC64: define dso_local <2 x i64> @bar(i128* %0, i128* %1)
+
+void vararg(int a, ...) {
+  // GNU64-LABEL: define{{.*}} void @vararg
+  // MSC64-LABEL: define{{.*}} void @vararg
+  __builtin_va_list ap;
+  __builtin_va_start(ap, a);
+  int128_t i = __builtin_va_arg(ap, int128_t);
+  // GNU64: bitcast i8* %argp.cur to i128**
+  // MSC64: bitcast i8* %argp.cur to i128**
+  __builtin_va_end(ap);
+}
Index: clang/test/CodeGen/mingw-long-double.c
===================================================================
--- clang/test/CodeGen/mingw-long-double.c
+++ clang/test/CodeGen/mingw-long-double.c
@@ -45,3 +45,16 @@
 // GNU32: declare dso_local void @__mulxc3
 // GNU64: declare dso_local void @__mulxc3
 // MSC64: declare dso_local void @__muldc3
+
+void VarArgLD(int a, ...) {
+  // GNU32-LABEL: define{{.*}} void @VarArgLD
+  // GNU64-LABEL: define{{.*}} void @VarArgLD
+  // MSC64-LABEL: define{{.*}} void @VarArgLD
+  __builtin_va_list ap;
+  __builtin_va_start(ap, a);
+  long double LD = __builtin_va_arg(ap, long double);
+  // GNU32: bitcast i8* %argp.cur to x86_fp80*
+  // GNU64: bitcast i8* %argp.cur to x86_fp80**
+  // MSC64: bitcast i8* %argp.cur to double*
+  __builtin_va_end(ap);
+}
Index: clang/lib/CodeGen/TargetInfo.cpp
===================================================================
--- clang/lib/CodeGen/TargetInfo.cpp
+++ clang/lib/CodeGen/TargetInfo.cpp
@@ -4358,15 +4358,10 @@
 
 Address WinX86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
                                     QualType Ty) const {
-
-  bool IsIndirect = false;
-
   // MS x64 ABI requirement: "Any argument that doesn't fit in 8 bytes, or is
   // not 1, 2, 4, or 8 bytes, must be passed by reference."
-  if (isAggregateTypeForABI(Ty) || Ty->isMemberPointerType()) {
-    uint64_t Width = getContext().getTypeSize(Ty);
-    IsIndirect = Width > 64 || !llvm::isPowerOf2_64(Width);
-  }
+  uint64_t Width = getContext().getTypeSize(Ty);
+  bool IsIndirect = Width > 64 || !llvm::isPowerOf2_64(Width);
 
   return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect,
                           CGF.getContext().getTypeInfoInChars(Ty),


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103452.349491.patch
Type: text/x-patch
Size: 2414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210603/ccb7f55a/attachment-0001.bin>


More information about the cfe-commits mailing list