From d0eb3b93e89f0ab83a2305eb0ec42076f8d46142 Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Wed, 2 Sep 2009 17:51:33 +0000 Subject: [PATCH] Packed unions should be packed. Fixes an assert Daniel reported. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80808 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGRecordLayoutBuilder.cpp | 3 +-- test/CodeGen/packed-union.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 test/CodeGen/packed-union.c diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp index ea5de5f2b1..74ef2eacc9 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/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/test/CodeGen/packed-union.c b/test/CodeGen/packed-union.c new file mode 100644 index 0000000000..d11d3a4902 --- /dev/null +++ b/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; + -- 2.50.1