]> granicus.if.org Git - clang/commitdiff
Fix an incorrect union layout assert. Fixes PR6164.
authorAnders Carlsson <andersca@mac.com>
Thu, 28 Jan 2010 18:22:03 +0000 (18:22 +0000)
committerAnders Carlsson <andersca@mac.com>
Thu, 28 Jan 2010 18:22:03 +0000 (18:22 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@94754 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGRecordLayoutBuilder.cpp
test/CodeGen/union.c

index 9f90ec5ff6e0a7ab74502eb306ad817589f3474b..cc474033c11b403009fdbc9828cec98b2978e936 100644 (file)
@@ -162,6 +162,8 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) {
   uint64_t Size = 0;
   unsigned Align = 0;
 
+  bool HasOnlyZeroSizedBitFields = true;
+  
   unsigned FieldNo = 0;
   for (RecordDecl::field_iterator Field = D->field_begin(),
        FieldEnd = D->field_end(); Field != FieldEnd; ++Field, ++FieldNo) {
@@ -181,6 +183,8 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) {
     } else
       Types.addFieldInfo(*Field, 0);
 
+    HasOnlyZeroSizedBitFields = false;
+    
     const llvm::Type *FieldTy =
       Types.ConvertTypeForMemRecursive(Field->getType());
     unsigned FieldAlign = Types.getTargetData().getABITypeAlignment(FieldTy);
@@ -207,7 +211,8 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) {
     }
   }
   if (!Align) {
-    assert((D->field_begin() == D->field_end()) && "LayoutUnion - Align 0");
+    assert(HasOnlyZeroSizedBitFields &&
+           "0-align record did not have all zero-sized bit-fields!");
     Align = 1;
   }
   
index b40a405597ac58ec329d061f91d0f2cfaca3f3e3..1883ca639b7e4e620b22672de8db6319cf067b0d 100644 (file)
@@ -39,3 +39,6 @@ int qfunc() {q buf; unsigned char* x = buf.x;}
 union RR {_Bool a : 1;} RRU;
 int RRF(void) {return RRU.a;}
 
+// PR6164
+typedef union T0 { unsigned int : 0; } T0;
+T0 t0;