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 java/10145 (the attribute aligned bug)


See the thread at http://gcc.gnu.org/ml/gcc/2003-03/msg01318.html for
discussion of this issue.

This is a minimal patch for 3.3, which fixes the bug Andrew reported and
also supports attribute aligned on zero-length bitfields.  I'm also
checking this in on the trunk, but will do something more comprehensive
there soon.

Tested i686-pc-linux-gnu.  Test in gcc.dg/align-1.c.

2003-03-30  Jason Merrill  <jason at redhat dot com>

	* stor-layout.c (update_alignment_for_field): Respect
	DECL_USER_ALIGN for zero-length bitfields, too.
	* c-decl.c (finish_struct): Don't set DECL_ALIGN for normal
	fields.
 	* cp/class.c (check_field_decl): Don't set DECL_ALIGN.

Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.356.2.3
diff -c -p -r1.356.2.3 c-decl.c
*** c-decl.c	12 Mar 2003 09:59:51 -0000	1.356.2.3
--- c-decl.c	30 Mar 2003 19:35:21 -0000
*************** finish_struct (t, fieldlist, attributes)
*** 5226,5243 ****
  	    }
  	}
  
-       else if (TREE_TYPE (x) != error_mark_node)
- 	{
- 	  unsigned int min_align = (DECL_PACKED (x) ? BITS_PER_UNIT
- 				    : TYPE_ALIGN (TREE_TYPE (x)));
- 
- 	  /* Non-bit-fields are aligned for their type, except packed
- 	     fields which require only BITS_PER_UNIT alignment.  */
- 	  DECL_ALIGN (x) = MAX (DECL_ALIGN (x), min_align);
- 	  if (! DECL_PACKED (x))
- 	    DECL_USER_ALIGN (x) |= TYPE_USER_ALIGN (TREE_TYPE (x));
- 	}
- 
        DECL_INITIAL (x) = 0;
  
        /* Detect flexible array member in an invalid context.  */
--- 5226,5231 ----
Index: stor-layout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stor-layout.c,v
retrieving revision 1.134.2.1
diff -c -p -r1.134.2.1 stor-layout.c
*** stor-layout.c	26 Jan 2003 09:02:25 -0000	1.134.2.1
--- stor-layout.c	30 Mar 2003 19:35:23 -0000
*************** update_alignment_for_field (rli, field, 
*** 758,764 ****
  	 within the structure.  */
        if (! integer_zerop (DECL_SIZE (field)))
  	rli->record_align = MAX (rli->record_align, desired_align);
!       else if (! DECL_PACKED (field))
  	desired_align = TYPE_ALIGN (type);
  
        /* A named bit field of declared type `int'
--- 758,764 ----
  	 within the structure.  */
        if (! integer_zerop (DECL_SIZE (field)))
  	rli->record_align = MAX (rli->record_align, desired_align);
!       else if (! DECL_PACKED (field) && !user_align)
  	desired_align = TYPE_ALIGN (type);
  
        /* A named bit field of declared type `int'
Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.499.2.10
diff -c -p -r1.499.2.10 class.c
*** cp/class.c	17 Mar 2003 12:00:25 -0000	1.499.2.10
--- cp/class.c	30 Mar 2003 19:35:31 -0000
*************** check_field_decl (field, t, cant_have_co
*** 3090,3104 ****
  	cp_error_at ("multiple fields in union `%T' initialized");
        *any_default_members = 1;
      }
- 
-   /* Non-bit-fields are aligned for their type, except packed fields
-      which require only BITS_PER_UNIT alignment.  */
-   DECL_ALIGN (field) = MAX (DECL_ALIGN (field), 
- 			    (DECL_PACKED (field) 
- 			     ? BITS_PER_UNIT
- 			     : TYPE_ALIGN (TREE_TYPE (field))));
-   if (! DECL_PACKED (field))
-     DECL_USER_ALIGN (field) |= TYPE_USER_ALIGN (TREE_TYPE (field));
  }
  
  /* Check the data members (both static and non-static), class-scoped
--- 3090,3095 ----

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