]> granicus.if.org Git - clang/commitdiff
Handle zero width bit fields in unions correctly (by ignoring them).
authorAnders Carlsson <andersca@mac.com>
Thu, 23 Jul 2009 04:00:39 +0000 (04:00 +0000)
committerAnders Carlsson <andersca@mac.com>
Thu, 23 Jul 2009 04:00:39 +0000 (04:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76847 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGRecordLayoutBuilder.cpp

index 2fe7e5765de19ad8b159652344bec4a17f88f22b..1631c43eb99d9f728739da564f11e9e08f9a7b04 100644 (file)
@@ -160,6 +160,15 @@ void CGRecordLayoutBuilder::LayoutUnion(const RecordDecl *D) {
        FieldEnd = D->field_end(); Field != FieldEnd; ++Field, ++FieldNo) {
     assert(Layout.getFieldOffset(FieldNo) == 0 && 
           "Union field offset did not start at the beginning of record!");
+
+    if (Field->isBitField()) {
+      uint64_t FieldSize = 
+        Field->getBitWidth()->EvaluateAsInt(Types.getContext()).getZExtValue();
+    
+      // Ignore zero sized bit fields.
+      if (FieldSize == 0)
+        continue;
+    }
     
     const llvm::Type *FieldTy = 
       Types.ConvertTypeForMemRecursive(Field->getType());