[cfe-commits] r101668 - in /cfe/trunk: lib/AST/RecordLayoutBuilder.cpp test/CodeGenCXX/bitfield-layout.cpp

Anders Carlsson andersca at mac.com
Sat Apr 17 13:21:41 PDT 2010


Author: andersca
Date: Sat Apr 17 15:21:41 2010
New Revision: 101668

URL: http://llvm.org/viewvc/llvm-project?rev=101668&view=rev
Log:
If a wide bit-field is inside a union its offset should always be 0.

Added:
    cfe/trunk/test/CodeGenCXX/bitfield-layout.cpp
Modified:
    cfe/trunk/lib/AST/RecordLayoutBuilder.cpp

Modified: cfe/trunk/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/RecordLayoutBuilder.cpp?rev=101668&r1=101667&r2=101668&view=diff
==============================================================================
--- cfe/trunk/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/trunk/lib/AST/RecordLayoutBuilder.cpp Sat Apr 17 15:21:41 2010
@@ -640,13 +640,16 @@
   // 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);

Added: cfe/trunk/test/CodeGenCXX/bitfield-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/bitfield-layout.cpp?rev=101668&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/bitfield-layout.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/bitfield-layout.cpp Sat Apr 17 15:21:41 2010
@@ -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;





More information about the cfe-commits mailing list