[llvm-commits] [125991] Fix num of bits required calculation for bitfields that

dpatel at apple.com dpatel at apple.com
Wed Apr 11 17:33:44 PDT 2007


Revision: 125991
Author:   dpatel
Date:     2007-04-11 17:33:44 -0700 (Wed, 11 Apr 2007)

Log Message:
-----------
Fix num of bits required calculation for bitfields that 
do not start at byte boundary.

Fix
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070409/047340.html

Modified Paths:
--------------
    apple-local/branches/llvm/gcc/llvm-types.cpp

Modified: apple-local/branches/llvm/gcc/llvm-types.cpp
===================================================================
--- apple-local/branches/llvm/gcc/llvm-types.cpp	2007-04-11 23:44:56 UTC (rev 125990)
+++ apple-local/branches/llvm/gcc/llvm-types.cpp	2007-04-12 00:33:44 UTC (rev 125991)
@@ -1287,11 +1287,11 @@
 
   if (StartOffsetInBits < FirstUnallocatedByte*8) {
 
+    unsigned AvailableBits = FirstUnallocatedByte * 8 - StartOffsetInBits;
     // This field's starting point is already allocated.
     if (StartOffsetFromByteBoundry == 0) {
       // This field starts at byte boundry. Need to allocate space
       // for additional bytes not yet allocated.
-      unsigned AvailableBits = FirstUnallocatedByte * 8 - StartOffsetInBits;
       unsigned NumBitsToAdd = FieldSizeInBits - AvailableBits;
       Info.addNewBitField(NumBitsToAdd, FirstUnallocatedByte);
       return;
@@ -1300,15 +1300,15 @@
     // Otherwise, this field's starting point is inside previously used byte. 
     // This happens with Packed bit fields. In this case one LLVM Field is
     // used to access previous field and current field.
-
     unsigned prevFieldTypeSizeInBits = 
-      Info.Elements.back()->getPrimitiveSizeInBits();
-    unsigned NumBitsRequired = FieldSizeInBits + 
-      (prevFieldTypeSizeInBits/8 - 1)*8 + StartOffsetFromByteBoundry;
+      Info.ElementSizeInBytes[Info.Elements.size() - 1] * 8;
 
+    unsigned NumBitsRequired = prevFieldTypeSizeInBits 
+      + (FieldSizeInBits - AvailableBits);
+
     if (NumBitsRequired > 64) {
       // Use bits from previous field.
-      NumBitsRequired = NumBitsRequired - FirstUnallocatedByte*8;
+      NumBitsRequired = FieldSizeInBits - AvailableBits;
     } else {
       // If type used to access previous field is not large enough then
       // remove previous field and insert new field that is large enough to





More information about the llvm-commits mailing list