[llvm-commits] CVS: llvm-gcc/gcc/llvm-types.c

Chris Lattner lattner at cs.uiuc.edu
Wed Nov 24 22:25:57 PST 2004



Changes in directory llvm-gcc/gcc:

llvm-types.c updated: 1.15 -> 1.16
---
Log message:

Fix PR461: http://llvm.cs.uiuc.edu/PR461  and Regression/CFrontend/2004-11-25-UnnamedBitfieldPadding.c


---
Diffs of the changes:  (+9 -4)

Index: llvm-gcc/gcc/llvm-types.c
diff -u llvm-gcc/gcc/llvm-types.c:1.15 llvm-gcc/gcc/llvm-types.c:1.16
--- llvm-gcc/gcc/llvm-types.c:1.15	Fri Aug  6 13:07:34 2004
+++ llvm-gcc/gcc/llvm-types.c	Thu Nov 25 00:25:45 2004
@@ -718,8 +718,9 @@
   } else if (DECL_NAME(field) == 0 &&      /* Is this an anonymous bitfield? */
              DECL_BIT_FIELD(field)) {
     unsigned NumPads;
+    unsigned DeclSize = GetDeclSize(field);
     /* Is it attempting to align the current offset to some value? */
-    if (GetDeclSize(field) == 0) {
+    if (DeclSize == 0) {
       NumPads = ByteAlignment - (*Size % ByteAlignment);
       if (NumPads == ByteAlignment) NumPads = 0;
       assert((*Size+NumPads) % ByteAlignment == 0 &&"Incorrect padding calc?");
@@ -732,10 +733,14 @@
       /* Otherwise we are just padding out for an unnamed bitfield.  This does
        * not affect alignment, so we just insert the appropriate number of
        * ubytes.  EndByte is the byte that the last bit of the unnamed bitfield
-       * falls into.
+       * falls into.  If we already padded out for this due to alignment, this
+       * is a noop.
        */
-      unsigned EndByte = (StartOffset+GetDeclSize(field)+7)/8;
-      NumPads = EndByte - *Size;
+      unsigned EndByte = (StartOffset+DeclSize+7)/8;
+      if (EndByte <= *Size)
+        NumPads = 0;          /* This padding already exists! */
+      else
+        NumPads = EndByte - *Size;
     }
 
     /* Add "NumPads" ubyte elements to the structure. */






More information about the llvm-commits mailing list