r279774 - [MS] Win64 va_arg should expect large arguments to be passed indirectly

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 25 13:42:26 PDT 2016


Author: rnk
Date: Thu Aug 25 15:42:26 2016
New Revision: 279774

URL: http://llvm.org/viewvc/llvm-project?rev=279774&view=rev
Log:
[MS] Win64 va_arg should expect large arguments to be passed indirectly

Fixes PR20569

Modified:
    cfe/trunk/lib/CodeGen/TargetInfo.cpp
    cfe/trunk/test/CodeGen/ms_abi.c

Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=279774&r1=279773&r2=279774&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Thu Aug 25 15:42:26 2016
@@ -3651,7 +3651,17 @@ void WinX86_64ABIInfo::computeInfo(CGFun
 
 Address WinX86_64ABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
                                     QualType Ty) const {
-  return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*indirect*/ false,
+
+  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);
+  }
+
+  return emitVoidPtrVAArg(CGF, VAListAddr, Ty, IsIndirect,
                           CGF.getContext().getTypeInfoInChars(Ty),
                           CharUnits::fromQuantity(8),
                           /*allowHigherAlign*/ false);

Modified: cfe/trunk/test/CodeGen/ms_abi.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ms_abi.c?rev=279774&r1=279773&r2=279774&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/ms_abi.c (original)
+++ cfe/trunk/test/CodeGen/ms_abi.c Thu Aug 25 15:42:26 2016
@@ -45,24 +45,27 @@ void __attribute__((ms_abi)) f4(int a, .
   // WIN64-NEXT: %[[AP_NEXT:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR]], i64 8
   // WIN64-NEXT: store i8* %[[AP_NEXT]], i8** %[[AP]]
   // WIN64-NEXT: bitcast i8* %[[AP_CUR]] to i32*
+  // FIXME: These are different now. We probably need __builtin_ms_va_arg.
   double _Complex c = __builtin_va_arg(ap, double _Complex);
   // FREEBSD: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
   // FREEBSD-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 16
   // FREEBSD-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
   // FREEBSD-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }*
   // WIN64: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
-  // WIN64-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 16
+  // WIN64-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 8
   // WIN64-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
-  // WIN64-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }*
+  // WIN64-NEXT: %[[CUR2:.*]] = bitcast i8* %[[AP_CUR2]] to { double, double }**
+  // WIN64-NEXT: load { double, double }*, { double, double }** %[[CUR2]]
   struct foo d = __builtin_va_arg(ap, struct foo);
   // FREEBSD: %[[AP_CUR3:.*]] = load i8*, i8** %[[AP]]
   // FREEBSD-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 16
   // FREEBSD-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
   // FREEBSD-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
   // WIN64: %[[AP_CUR3:.*]] = load i8*, i8** %[[AP]]
-  // WIN64-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 16
+  // WIN64-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 8
   // WIN64-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
-  // WIN64-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
+  // WIN64-NEXT: %[[CUR3:.*]] = bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
+  // WIN64-NEXT: load %[[STRUCT_FOO]]*, %[[STRUCT_FOO]]** %[[CUR3]]
   __builtin_ms_va_list ap2;
   __builtin_ms_va_copy(ap2, ap);
   // FREEBSD: %[[AP_VAL:.*]] = load i8*, i8** %[[AP]]
@@ -88,12 +91,12 @@ void f5(int a, ...) {
   // WIN64-NEXT: bitcast i8* %[[AP_CUR]] to i32*
   double _Complex c = __builtin_va_arg(ap, double _Complex);
   // WIN64: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
-  // WIN64-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 16
+  // WIN64-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 8
   // WIN64-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
   // WIN64-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }*
   struct foo d = __builtin_va_arg(ap, struct foo);
   // WIN64: %[[AP_CUR3:.*]] = load i8*, i8** %[[AP]]
-  // WIN64-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 16
+  // WIN64-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 8
   // WIN64-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
   // WIN64-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
   __builtin_va_list ap2;
@@ -124,7 +127,7 @@ void __attribute__((sysv_abi)) f6(__buil
   // FREEBSD-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
   // FREEBSD-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }*
   // WIN64: %[[AP_CUR2:.*]] = load i8*, i8** %[[AP]]
-  // WIN64-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 16
+  // WIN64-NEXT: %[[AP_NEXT2:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR2]], i64 8
   // WIN64-NEXT: store i8* %[[AP_NEXT2]], i8** %[[AP]]
   // WIN64-NEXT: bitcast i8* %[[AP_CUR2]] to { double, double }*
   struct foo d = __builtin_va_arg(ap, struct foo);
@@ -133,7 +136,7 @@ void __attribute__((sysv_abi)) f6(__buil
   // FREEBSD-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
   // FREEBSD-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
   // WIN64: %[[AP_CUR3:.*]] = load i8*, i8** %[[AP]]
-  // WIN64-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 16
+  // WIN64-NEXT: %[[AP_NEXT3:.*]] = getelementptr inbounds i8, i8* %[[AP_CUR3]], i64 8
   // WIN64-NEXT: store i8* %[[AP_NEXT3]], i8** %[[AP]]
   // WIN64-NEXT: bitcast i8* %[[AP_CUR3]] to %[[STRUCT_FOO]]*
   __builtin_ms_va_list ap2;




More information about the cfe-commits mailing list