]> granicus.if.org Git - clang/commitdiff
If a wide bit-field is inside a union its offset should always be 0.
authorAnders Carlsson <andersca@mac.com>
Sat, 17 Apr 2010 20:21:41 +0000 (20:21 +0000)
committerAnders Carlsson <andersca@mac.com>
Sat, 17 Apr 2010 20:21:41 +0000 (20:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101668 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/RecordLayoutBuilder.cpp
test/CodeGenCXX/bitfield-layout.cpp [new file with mode: 0644]

index d1de70a7ab8413155cbf68d663b023b8addda237..a674ad797091c211f679d8434d95f1eb2024a2b8 100644 (file)
@@ -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 (file)
index 0000000..c77c925
--- /dev/null
@@ -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;