]> granicus.if.org Git - clang/commitdiff
Fix the meaning of an "empty" record for the case of a zero-length array. Use isEmpt...
authorEli Friedman <eli.friedman@gmail.com>
Fri, 18 Nov 2011 03:47:20 +0000 (03:47 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Fri, 18 Nov 2011 03:47:20 +0000 (03:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144971 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/TargetInfo.cpp
test/CodeGen/x86_32-arguments-darwin.c

index 33291dd5527b1a92894434b9b371d4a2675e3b58..a2e15107f50c13e01213766f55626e8dde82c9c7 100644 (file)
@@ -117,10 +117,14 @@ static bool isEmptyField(ASTContext &Context, const FieldDecl *FD,
 
   QualType FT = FD->getType();
 
-    // Constant arrays of empty records count as empty, strip them off.
+  // Constant arrays of empty records count as empty, strip them off.
+  // Constant arrays of zero length always count as empty.
   if (AllowArrays)
-    while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT))
+    while (const ConstantArrayType *AT = Context.getAsConstantArrayType(FT)) {
+      if (AT->getSize() == 0)
+        return true;
       FT = AT->getElementType();
+    }
 
   const RecordType *RT = FT->getAs<RecordType>();
   if (!RT)
@@ -684,7 +688,7 @@ ABIArgInfo X86_32ABIInfo::classifyArgumentType(QualType Ty) const {
     }
 
     // Ignore empty structs/unions.
-    if (Ty->isRecordType() && getContext().getTypeSize(Ty) == 0)
+    if (isEmptyRecord(Context, Ty, true))
       return ABIArgInfo::getIgnore();
 
     // Expand small (<= 128-bit) record types when we know that the stack layout
index 31802ab8a322f3240d3a1ccb1f36214e66c1f92c..cc10580f8f4205f711ed257287f6b77d4d0d1257 100644 (file)
@@ -316,3 +316,11 @@ int f63(int i, ...) {
   __builtin_va_end(ap);
   return s.y;
 }
+
+// CHECK: define i32 @f64(%struct.s64* nocapture byval align 4 %x)
+struct s64 { signed char a[0]; signed char b[]; };
+void f64(struct s64 x) {}
+
+// CHECK: define float @f65()
+struct s65 { signed char a[0]; float b; };
+struct s65 f65() { return (struct s65){{},2}; }