]> granicus.if.org Git - clang/commitdiff
Darwin x86-32: Multi-dimensional arrays were not handled correctly,
authorDaniel Dunbar <daniel@zuster.org>
Mon, 11 May 2009 23:01:34 +0000 (23:01 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 11 May 2009 23:01:34 +0000 (23:01 +0000)
spotted by Eli!

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

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

index 36b6b92ab8213a9983957d1370e2c65e097c886e..c46e7901d9f518428cfab520c3465841a22621b2 100644 (file)
@@ -166,10 +166,9 @@ static bool isEmptyField(ASTContext &Context, const FieldDecl *FD) {
     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;
+  // Constant arrays of empty records count as empty, strip them off.
+  while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT))
+    FT = AT->getElementType();
   
   return isEmptyRecord(Context, FT);
 }
@@ -218,14 +217,18 @@ static const Type *isSingleElementStruct(QualType T, ASTContext &Context) {
     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();
-
+    // If we already found an element then this isn't a single-element
+    // struct.
     if (Found)
       return 0;
 
+    // Treat single element arrays as the element.
+    while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT)) {
+      if (AT->getSize().getZExtValue() != 1)
+        break;
+      FT = AT->getElementType();
+    }
+
     if (!CodeGenFunction::hasAggregateLLVMType(FT)) {
       Found = FT.getTypePtr();
     } else {
index b9853d809e9b75f78b904fe24e1255c29e06449e..e31a09cbc739b85cf25d6815cc9788adf8df5212 100644 (file)
@@ -145,4 +145,10 @@ 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: grep 'define i16 @f36()' %t &&
+struct s36 { struct { int : 0 } a[2][10]; char b; char c; } f36(void) {}
+
+// RUN: grep 'define float @f37()' %t &&
+struct s37 { float c[1][1]; } f37(void) {}
+
 // RUN: true