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

Daniel Dunbar daniel at zuster.org
Mon Apr 27 11:31:32 PDT 2009


Author: ddunbar
Date: Mon Apr 27 13:31:32 2009
New Revision: 70220

URL: http://llvm.org/viewvc/llvm-project?rev=70220&view=rev
Log:
x86-32 ABI: Fix crash on return of structure with flexible array
member.

Also, spell bitfield more consistently as bit-field.

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=70220&r1=70219&r2=70220&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Mon Apr 27 13:31:32 2009
@@ -237,7 +237,7 @@
     if (!is32Or64BitBasicType(FD->getType(), Context))
       return false;
     
-    // FIXME: Reject bitfields wholesale; there are two problems, we
+    // FIXME: Reject bit-fields wholesale; there are two problems, we
     // don't know how to expand them yet, and the predicate for
     // telling if a bitfield still counts as "basic" is more
     // complicated than what we were doing previously.
@@ -342,7 +342,7 @@
          e = RT->getDecl()->field_end(Context); i != e; ++i) {
     const FieldDecl *FD = *i;
     
-    // FIXME: Reject bitfields wholesale for now; this is incorrect.
+    // FIXME: Reject bit-fields wholesale for now; this is incorrect.
     if (FD->isBitField())
       return false;
 
@@ -385,9 +385,15 @@
 
     return ABIArgInfo::getDirect();
   } else if (CodeGenFunction::hasAggregateLLVMType(RetTy)) {
+    // Structures with flexible arrays are always indirect.
+    if (const RecordType *RT = RetTy->getAsStructureType())
+      if (RT->getDecl()->hasFlexibleArrayMember())
+        return ABIArgInfo::getIndirect(0);
+
     // Outside of Darwin, structs and unions are always indirect.
     if (!IsDarwin && !RetTy->isAnyComplexType())
       return ABIArgInfo::getIndirect(0);
+
     // Classify "single element" structs as their element type.
     if (const Type *SeltTy = isSingleElementStruct(RetTy, Context)) {
       if (const BuiltinType *BT = SeltTy->getAsBuiltinType()) {
@@ -766,7 +772,7 @@
       // AMD64-ABI 3.2.3p2: Rule 1. If ..., or it contains unaligned
       // fields, it has class MEMORY.
       //
-      // Note, skip this test for bitfields, see below.
+      // Note, skip this test for bit-fields, see below.
       if (!BitField && Offset % Context.getTypeAlign(i->getType())) {
         Lo = Memory;
         return;
@@ -780,7 +786,7 @@
       // NO_CLASS.
       Class FieldLo, FieldHi;
       
-      // Bitfields require special handling, they do not force the
+      // Bit-fields require special handling, they do not force the
       // structure to be passed in memory even if unaligned, and
       // therefore they can straddle an eightbyte.
       if (BitField) {

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=70220&r1=70219&r2=70220&view=diff

==============================================================================
--- cfe/trunk/test/CodeGen/x86_32-arguments.c (original)
+++ cfe/trunk/test/CodeGen/x86_32-arguments.c Mon Apr 27 13:31:32 2009
@@ -123,4 +123,7 @@
 struct s26 { struct { char a, b; } a; struct { char a, b } b; } f26(void) {}
 struct s27 { struct { char a, b, c; } a; struct { char a } b; } f27(void) {}
 
+// RUN: grep 'void @f28(%.truct.s28\* noalias sret %agg.result)' %t &&
+struct s28 { int a; int b[] } f28(void) {}
+
 // RUN: true





More information about the cfe-commits mailing list