]> granicus.if.org Git - clang/commitdiff
Correctly Load Mixed FP-GP Variadic Arguments for x86-64.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 24 Jun 2014 20:01:50 +0000 (20:01 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 24 Jun 2014 20:01:50 +0000 (20:01 +0000)
According to the x86-64 ABI, structures with both floating point and
integer members are split between floating-point and general purpose
registers, and consecutive 32-bit floats can be packed into a single
floating point register.

In the case of variadic functions these are stored to memory and the position
recorded in the va_list. This was already correctly implemented in
llvm.va_start.

The problem is that the code in clang for implementing va_arg was reading
floating point registers from the wrong location.

Patch by Thomas Jablin.

Fixes PR20018.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211626 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/TargetInfo.cpp
test/CodeGen/variadic-gpfp-x86.c [new file with mode: 0644]

index 3a7ca335be7f89b2244d37f76bb9ba4e84632336..29899eec2e1deeaa2c5f0d84dc2ee0d6b7780c06 100644 (file)
@@ -2590,8 +2590,8 @@ llvm::Value *X86_64ABIInfo::EmitVAArg(llvm::Value *VAListAddr, QualType Ty,
     llvm::Type *PTyHi = llvm::PointerType::getUnqual(TyHi);
     llvm::Value *GPAddr = CGF.Builder.CreateGEP(RegAddr, gp_offset);
     llvm::Value *FPAddr = CGF.Builder.CreateGEP(RegAddr, fp_offset);
-    llvm::Value *RegLoAddr = TyLo->isFloatingPointTy() ? FPAddr : GPAddr;
-    llvm::Value *RegHiAddr = TyLo->isFloatingPointTy() ? GPAddr : FPAddr;
+    llvm::Value *RegLoAddr = TyLo->isFPOrFPVectorTy() ? FPAddr : GPAddr;
+    llvm::Value *RegHiAddr = TyLo->isFPOrFPVectorTy() ? GPAddr : FPAddr;
     llvm::Value *V =
       CGF.Builder.CreateLoad(CGF.Builder.CreateBitCast(RegLoAddr, PTyLo));
     CGF.Builder.CreateStore(V, CGF.Builder.CreateStructGEP(Tmp, 0));
diff --git a/test/CodeGen/variadic-gpfp-x86.c b/test/CodeGen/variadic-gpfp-x86.c
new file mode 100644 (file)
index 0000000..735c4be
--- /dev/null
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s
+
+struct Bar {
+ float f1;
+ float f2;
+ unsigned u;
+};
+
+struct Bar foo(__builtin_va_list ap) {
+  return __builtin_va_arg(ap, struct Bar);
+// CHECK: [[FPOP:%.*]] = getelementptr inbounds %struct.__va_list_tag* {{.*}}, i32 0, i32 1
+// CHECK: [[FPO:%.*]] = load i32* [[FPOP]]
+// CHECK: [[FPVEC:%.*]] = getelementptr i8* {{.*}}, i32 [[FPO]]
+// CHECK: bitcast i8* [[FPVEC]] to <2 x float>*
+}