]> granicus.if.org Git - clang/commitdiff
Darwin x86_32: When coercing a "single element" structure, make sure
authorDaniel Dunbar <daniel@zuster.org>
Fri, 8 May 2009 21:30:11 +0000 (21:30 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 8 May 2009 21:30:11 +0000 (21:30 +0000)
to use a wide enough type. This might be wider than the "single
element"'s type in the presence of padding bit-fields.
 - Darwin x86_32 now passes the first 1k ABI tests with bit-field
   generation enabled.

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

lib/CodeGen/CGCall.cpp
test/CodeGen/x86_32-arguments.c

index 883eb5ede483cd445538705355ef25bafb378b28..49c6f0e3a611f3c9f4dec8aaf1aae632dfb64296 100644 (file)
@@ -404,15 +404,19 @@ ABIArgInfo X86_32ABIInfo::classifyReturnType(QualType RetTy,
     // Classify "single element" structs as their element type.
     if (const Type *SeltTy = isSingleElementStruct(RetTy, Context)) {
       if (const BuiltinType *BT = SeltTy->getAsBuiltinType()) {
-        // FIXME: This is gross, it would be nice if we could just
-        // pass back SeltTy and have clients deal with it. Is it worth
-        // supporting coerce to both LLVM and clang Types?
         if (BT->isIntegerType()) {
-          uint64_t Size = Context.getTypeSize(SeltTy);
+          // We need to use the size of the structure, padding
+          // bit-fields can adjust that to be larger than the single
+          // element type.
+          uint64_t Size = Context.getTypeSize(RetTy);
           return ABIArgInfo::getCoerce(llvm::IntegerType::get((unsigned) Size));
         } else if (BT->getKind() == BuiltinType::Float) {
+          assert(Context.getTypeSize(RetTy) == Context.getTypeSize(SeltTy) &&
+                 "Unexpect single element structure size!");
           return ABIArgInfo::getCoerce(llvm::Type::FloatTy);
         } else if (BT->getKind() == BuiltinType::Double) {
+          assert(Context.getTypeSize(RetTy) == Context.getTypeSize(SeltTy) &&
+                 "Unexpect single element structure size!");
           return ABIArgInfo::getCoerce(llvm::Type::DoubleTy);
         }
       } else if (SeltTy->isPointerType()) {
index c75734e5a126d24c7ff272bceb144b40d1f30862..0690639ab17c3624e54aa43c251bce68f64b2624 100644 (file)
@@ -133,4 +133,10 @@ struct s30 { char a; char b : 4; } f30(void) {}
 // RUN: grep 'define float @f31()' %t &&
 struct s31 { char : 0; float b; char : 0} f31(void) {}
 
+// RUN: grep 'define i32 @f32()' %t &&
+struct s32 { char a; unsigned : 0; } f32(void) {}
+
+// RUN: grep 'define float @f33()' %t &&
+struct s33 { float a; long long : 0; } f33(void) {}
+
 // RUN: true