[llvm-branch-commits] [cfe-branch] r102076 - in /cfe/branches/Apple/williamson: lib/AST/RecordLayoutBuilder.cpp test/CodeGenCXX/bitfield-layout.cpp

Daniel Dunbar daniel at zuster.org
Thu Apr 22 10:01:24 PDT 2010


Author: ddunbar
Date: Thu Apr 22 12:01:24 2010
New Revision: 102076

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

Added:
    cfe/branches/Apple/williamson/test/CodeGenCXX/bitfield-layout.cpp
Modified:
    cfe/branches/Apple/williamson/lib/AST/RecordLayoutBuilder.cpp

Modified: cfe/branches/Apple/williamson/lib/AST/RecordLayoutBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/williamson/lib/AST/RecordLayoutBuilder.cpp?rev=102076&r1=102075&r2=102076&view=diff
==============================================================================
--- cfe/branches/Apple/williamson/lib/AST/RecordLayoutBuilder.cpp (original)
+++ cfe/branches/Apple/williamson/lib/AST/RecordLayoutBuilder.cpp Thu Apr 22 12:01:24 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/branches/Apple/williamson/test/CodeGenCXX/bitfield-layout.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/williamson/test/CodeGenCXX/bitfield-layout.cpp?rev=102076&view=auto
==============================================================================
--- cfe/branches/Apple/williamson/test/CodeGenCXX/bitfield-layout.cpp (added)
+++ cfe/branches/Apple/williamson/test/CodeGenCXX/bitfield-layout.cpp Thu Apr 22 12:01:24 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 llvm-branch-commits mailing list