]> granicus.if.org Git - clang/commitdiff
Packed unions should be packed. Fixes an assert Daniel reported.
authorAnders Carlsson <andersca@mac.com>
Wed, 2 Sep 2009 17:51:33 +0000 (17:51 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 2 Sep 2009 17:51:33 +0000 (17:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80808 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGRecordLayoutBuilder.cpp
test/CodeGen/packed-union.c [new file with mode: 0644]

index ea5de5f2b1e97389a31c2fbb4a8ac42b5a96c443..74ef2eacc987975c9b5b71e83bc3c61118af7a0e 100644 (file)
@@ -28,14 +28,13 @@ using namespace CodeGen;
 
 void CGRecordLayoutBuilder::Layout(const RecordDecl *D) {
   Alignment = Types.getContext().getASTRecordLayout(D).getAlignment() / 8;
+  Packed = D->hasAttr<PackedAttr>();
 
   if (D->isUnion()) {
     LayoutUnion(D);
     return;
   }
 
-  Packed = D->hasAttr<PackedAttr>();
-  
   if (LayoutFields(D))
     return;
   
diff --git a/test/CodeGen/packed-union.c b/test/CodeGen/packed-union.c
new file mode 100644 (file)
index 0000000..d11d3a4
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: clang-cc -triple x86_64-apple-darwin10 -emit-llvm %s -o %t &&
+
+// RUN: grep "struct._attrs = type <{ i32, i8 }>" %t &&
+typedef struct _attrs {
+        unsigned file_attributes;
+        unsigned char filename_length;
+} __attribute__((__packed__)) attrs;
+
+// RUN: grep "union._attr_union = type <{ i32, i8 }>" %t
+typedef union _attr_union {
+  attrs file_attrs;
+  unsigned owner_id;
+} __attribute__((__packed__)) attr_union;
+
+attr_union u;
+