This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch for Microsoft bitfield layout


A minor fix to the recent Microsoft bitfield changes.  This code
in stor-layout.c:place_field():

     if (rli->remaining_in_alignment < bitsize)
       {
         /* out of bits; bump up to next 'word'.  */
         rli->bitpos = size_binop (PLUS_EXPR,
                             type_size,
                             DECL_FIELD_BIT_OFFSET(rli->prev_field));
         rli->prev_field = field;
         rli->remaining_in_alignment = TREE_INT_CST_LOW (type_size);
       }

moves the 'cursor' from the end of the previous bitfield to
the end of the underlying allocation area.  AFAICT, it should
update rli->offset as well, in case the 'end of bitfield'
position had been normalised.

E.g. say there are four consecutive fields of the form 'int ... : 32'.
If the position is written (offset, bitpos) then we have:

        Cursor after above code   Start of field   End of field
   1    (0, 0)                    (0, 0)           (0, 32)
   2    (0, 32)                   (0, 32)          (1, 0)
   3    (1, 64)                   (2, 0)           (2, 32)
   4    (2, 32)                   (2, 32)          (3, 0)

and the structure is 6 bytes long instead of the expected 4.

Patch tested on sh64-elf.  OK to install?

Richard


	* stor-layout.c (place_field): Update rli->offset as well as
	rli->bitpos.

Index: stor-layout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stor-layout.c,v
retrieving revision 1.133
diff -c -d -p -F^[(a-zA-Z0-9_^#] -r1.133 stor-layout.c
*** stor-layout.c	1 Oct 2002 18:44:49 -0000	1.133
--- stor-layout.c	12 Nov 2002 12:48:08 -0000
*************** #endif
*** 1036,1041 ****
--- 1036,1042 ----
  	      if (rli->remaining_in_alignment < bitsize)
  		{
  		  /* out of bits; bump up to next 'word'.  */
+ 		  rli->offset = DECL_FIELD_OFFSET (rli->prev_field);
  		  rli->bitpos = size_binop (PLUS_EXPR,
  				      type_size,
  				      DECL_FIELD_BIT_OFFSET(rli->prev_field));
*** /dev/null	Tue Nov 14 21:44:43 2000
--- testsuite/gcc.dg/bitfld-5.c	Tue Nov 12 12:46:32 2002
***************
*** 0 ****
--- 1,12 ----
+ /* { dg-options "" } */
+ #include <limits.h>
+ 
+ struct s
+ {
+   int i1 : sizeof (int) * CHAR_BIT;
+   int i2 : sizeof (int) * CHAR_BIT;
+   int i3 : sizeof (int) * CHAR_BIT;
+   int i4 : sizeof (int) * CHAR_BIT;
+ };
+ 
+ int f[sizeof (struct s) != sizeof (int) * 4 ? -1 : 1];


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]