[cfe-commits] r71461 - in /cfe/trunk: lib/CodeGen/CGCall.cpp test/CodeGen/x86_32-arguments.c

Daniel Dunbar daniel at zuster.org
Mon May 11 11:58:49 PDT 2009


Author: ddunbar
Date: Mon May 11 13:58:49 2009
New Revision: 71461

URL: http://llvm.org/viewvc/llvm-project?rev=71461&view=rev
Log:
Darwin x86_32: Treat records with unnamed bit-fields as "empty".

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/test/CodeGen/x86_32-arguments.c

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=71461&r1=71460&r2=71461&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon May 11 13:58:49 2009
@@ -157,8 +157,25 @@
 
 /***/
 
-/// isEmptyRecord - Return true iff a structure has no non-empty
-/// members. Note that a structure with a flexible array member is not
+static bool isEmptyRecord(ASTContext &Context, QualType T);
+
+/// isEmptyField - Return true iff a the field is "empty", that is it
+/// is an unnamed bit-field or an (array of) empty record(s).
+static bool isEmptyField(ASTContext &Context, const FieldDecl *FD) {
+  if (FD->isUnnamedBitfield())
+    return true;
+
+  QualType FT = FD->getType();
+  // Arrays of empty records count as empty.
+  if (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT))
+    if (isEmptyRecord(Context, AT->getElementType()))
+      return true;
+  
+  return isEmptyRecord(Context, FT);
+}
+
+/// isEmptyRecord - Return true iff a structure contains only empty
+/// fields. Note that a structure with a flexible array member is not
 /// considered empty.
 static bool isEmptyRecord(ASTContext &Context, QualType T) {
   const RecordType *RT = T->getAsRecordType();
@@ -168,11 +185,9 @@
   if (RD->hasFlexibleArrayMember())
     return false;
   for (RecordDecl::field_iterator i = RD->field_begin(Context), 
-         e = RD->field_end(Context); i != e; ++i) {
-    const FieldDecl *FD = *i;
-    if (!isEmptyRecord(Context, FD->getType()))
+         e = RD->field_end(Context); i != e; ++i)
+    if (!isEmptyField(Context, *i))
       return false;
-  }
   return true;
 }
 
@@ -199,15 +214,15 @@
     const FieldDecl *FD = *i;
     QualType FT = FD->getType();
 
+    // Ignore empty fields.
+    if (isEmptyField(Context, FD))
+      continue;
+
     // Treat single element arrays as the element
     if (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT))
       if (AT->getSize().getZExtValue() == 1)
         FT = AT->getElementType();
 
-    // Ignore empty records and padding bit-fields.
-    if (isEmptyRecord(Context, FT) || FD->isUnnamedBitfield())
-      continue;
-
     if (Found)
       return 0;
 
@@ -345,17 +360,10 @@
          e = RT->getDecl()->field_end(Context); i != e; ++i) {
     const FieldDecl *FD = *i;
     
-    // Empty structures are ignored.
-    if (isEmptyRecord(Context, FD->getType()))
+    // Empty fields are ignored.
+    if (isEmptyField(Context, FD))
       continue;
 
-    // As are arrays of empty structures, but not generally, so we
-    // can't add this test higher in this routine.
-    if (const ConstantArrayType *AT = 
-        Context.getAsConstantArrayType(FD->getType()))
-      if (isEmptyRecord(Context, AT->getElementType()))
-        continue;
-
     // Check fields recursively.
     if (!shouldReturnTypeInRegister(FD->getType(), Context))
       return false;

Modified: cfe/trunk/test/CodeGen/x86_32-arguments.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/x86_32-arguments.c?rev=71461&r1=71460&r2=71461&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/x86_32-arguments.c (original)
+++ cfe/trunk/test/CodeGen/x86_32-arguments.c Mon May 11 13:58:49 2009
@@ -139,4 +139,10 @@
 // RUN: grep 'define float @f33()' %t &&
 struct s33 { float a; long long : 0; } f33(void) {}
 
+// RUN: grep 'define float @f34()' %t &&
+struct s34 { struct { int : 0 } a; float b; } f34(void) {}
+
+// RUN: grep 'define i16 @f35()' %t &&
+struct s35 { struct { int : 0 } a; char b; char c; } f35(void) {}
+
 // RUN: true





More information about the cfe-commits mailing list