r202562 - Fixed an assertion failure related to bitfield lowering.

Warren Hunt whunt at google.com
Fri Feb 28 16:38:40 PST 2014


Author: whunt
Date: Fri Feb 28 18:38:40 2014
New Revision: 202562

URL: http://llvm.org/viewvc/llvm-project?rev=202562&view=rev
Log:
Fixed an assertion failure related to bitfield lowering.

When lowering a bitfield, CGRecordLowering would assign the wrong 
storage type to a bitfield in some cases and trigger an assertion.  In 
these cases the layout was still correct, just the bitfield info was 
wrong.


Modified:
    cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
    cfe/trunk/test/CodeGen/union.c

Modified: cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp?rev=202562&r1=202561&r2=202562&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRecordLayoutBuilder.cpp Fri Feb 28 18:38:40 2014
@@ -277,6 +277,7 @@ void CGRecordLowering::lower(bool NVBase
 }
 
 void CGRecordLowering::lowerUnion() {
+  CharUnits LayoutSize = Layout.getSize();
   llvm::Type *StorageType = 0;
   // Compute zero-initializable status.
   if (!D->field_empty() && !isZeroInitializable(*D->field_begin()))
@@ -293,7 +294,10 @@ void CGRecordLowering::lowerUnion() {
       // Skip 0 sized bitfields.
       if (Field->getBitWidthValue(Context) == 0)
         continue;
-      setBitFieldInfo(*Field, CharUnits::Zero(), getStorageType(*Field));
+      llvm::Type *FieldType = getStorageType(*Field);
+      if (LayoutSize < getSize(FieldType))
+        FieldType = getByteArrayType(LayoutSize);
+      setBitFieldInfo(*Field, CharUnits::Zero(), FieldType);
     }
     Fields[*Field] = 0;
     llvm::Type *FieldType = getStorageType(*Field);
@@ -304,7 +308,6 @@ void CGRecordLowering::lowerUnion() {
         getSize(FieldType) > getSize(StorageType)))
       StorageType = FieldType;
   }
-  CharUnits LayoutSize = Layout.getSize();
   // If we have no storage type just pad to the appropriate size and return.
   if (!StorageType)
     return appendPaddingBytes(LayoutSize);

Modified: cfe/trunk/test/CodeGen/union.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/union.c?rev=202562&r1=202561&r2=202562&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/union.c (original)
+++ cfe/trunk/test/CodeGen/union.c Fri Feb 28 18:38:40 2014
@@ -44,3 +44,16 @@ typedef union T0 { unsigned int : 0; } T
 T0 t0;
 
 union { int large_bitfield: 31; char c } u2;
+
+struct dt_t_s {
+  union {
+    long long u : 56;
+  } __attribute__((packed));
+};
+struct {
+  struct {
+    struct {
+      struct dt_t_s t;
+    };
+  };
+} a;





More information about the cfe-commits mailing list