From faaec2234f21bf175dd05c723072202cdf39cb2f Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Thu, 23 Jul 2009 21:16:33 +0000 Subject: [PATCH] Correct a thinko in bitfield layout code. Fixes PR4611. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76898 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGRecordLayoutBuilder.cpp | 6 ++---- test/CodeGen/PR4611-bitfield-layout.c | 6 ++++++ 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 test/CodeGen/PR4611-bitfield-layout.c diff --git a/lib/CodeGen/CGRecordLayoutBuilder.cpp b/lib/CodeGen/CGRecordLayoutBuilder.cpp index 2d10b1f030..455b92996a 100644 --- a/lib/CodeGen/CGRecordLayoutBuilder.cpp +++ b/lib/CodeGen/CGRecordLayoutBuilder.cpp @@ -88,10 +88,8 @@ void CGRecordLayoutBuilder::LayoutBitField(const FieldDecl *D, AppendBytes(NumBytesToAppend); - if (!NumBytesToAppend) - BitsAvailableInLastField -= FieldSize; - else - BitsAvailableInLastField = NumBytesToAppend * 8 - FieldSize; + BitsAvailableInLastField = + getNextFieldOffsetInBytes() * 8 - (FieldOffset + FieldSize); } bool CGRecordLayoutBuilder::LayoutField(const FieldDecl *D, diff --git a/test/CodeGen/PR4611-bitfield-layout.c b/test/CodeGen/PR4611-bitfield-layout.c new file mode 100644 index 0000000000..ef698d5ab3 --- /dev/null +++ b/test/CodeGen/PR4611-bitfield-layout.c @@ -0,0 +1,6 @@ +// RUN: clang-cc -triple i386-unknown-unknown %s -emit-llvm -o %t && +// RUN: grep "struct.object_entry = type <{ i8, i8, i8, i8 }>" %t + +struct object_entry { + unsigned int type:3, pack_id:16, depth:13; +} entries; -- 2.40.0