diff --git a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp index ea5de5f2b1e9..74ef2eacc987 100644 --- a/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/clang/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -28,14 +28,13 @@ using namespace CodeGen; void CGRecordLayoutBuilder::Layout(const RecordDecl *D) { Alignment = Types.getContext().getASTRecordLayout(D).getAlignment() / 8; + Packed = D->hasAttr(); if (D->isUnion()) { LayoutUnion(D); return; } - Packed = D->hasAttr(); - if (LayoutFields(D)) return; diff --git a/clang/test/CodeGen/packed-union.c b/clang/test/CodeGen/packed-union.c new file mode 100644 index 000000000000..d11d3a490234 --- /dev/null +++ b/clang/test/CodeGen/packed-union.c @@ -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; +