diff options
-rw-r--r-- | lib/AST/RecordLayoutBuilder.cpp | 11 | ||||
-rw-r--r-- | test/CodeGenCXX/bitfield-layout.cpp | 9 |
2 files changed, 16 insertions, 4 deletions
diff --git a/lib/AST/RecordLayoutBuilder.cpp b/lib/AST/RecordLayoutBuilder.cpp index d1de70a7ab..a674ad7970 100644 --- a/lib/AST/RecordLayoutBuilder.cpp +++ b/lib/AST/RecordLayoutBuilder.cpp @@ -640,13 +640,16 @@ void ASTRecordLayoutBuilder::LayoutWideBitField(uint64_t FieldSize, // We're not going to use any of the unfilled bits in the last byte. UnfilledBitsInLastByte = 0; - // The bitfield is allocated starting at the next offset aligned appropriately - // for T', with length n bits. - uint64_t FieldOffset = llvm::RoundUpToAlignment(DataSize, TypeAlign); - + uint64_t FieldOffset; + if (IsUnion) { DataSize = std::max(DataSize, FieldSize); + FieldOffset = 0; } else { + // The bitfield is allocated starting at the next offset aligned appropriately + // for T', with length n bits. + FieldOffset = llvm::RoundUpToAlignment(DataSize, TypeAlign); + uint64_t NewSizeInBits = FieldOffset + FieldSize; DataSize = llvm::RoundUpToAlignment(NewSizeInBits, 8); diff --git a/test/CodeGenCXX/bitfield-layout.cpp b/test/CodeGenCXX/bitfield-layout.cpp new file mode 100644 index 0000000000..c77c925d87 --- /dev/null +++ b/test/CodeGenCXX/bitfield-layout.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s + +// CHECK: = type { i32, [4 x i8] } +union Test1 { + int a; + int b: 39; +}; + +Test1 t1; |