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]

RFC: PATCH to layout_decl for middle-end/27945


Since Kenner never answered my question about the motivation for not packing VLA fields, I'm just going to check this in. I got no Ada regressions on ia64, a STRICT_ALIGNMENT target, so it seems that Ada doesn't need this exception anymore. If it does, it can go in the front end.

Tested ia64-unknown-linux-gnu, applied to trunk. Note that this is an ABI change/fix; packed has had no effect on variable size fields since 3.4. Mark, what's your opinion about which branches this should go on?

2007-09-11  Jason Merrill  <jason@redhat.com>

	PR middle-end/27945
	* stor-layout.c (layout_decl): Do pack variable size fields.	

Index: stor-layout.c
===================================================================
*** stor-layout.c	(revision 128377)
--- stor-layout.c	(working copy)
*************** layout_decl (tree decl, unsigned int kno
*** 414,431 ****
        else
  	do_type_align (type, decl);
  
!       /* If the field is of variable size, we can't misalign it since we
! 	 have no way to make a temporary to align the result.  But this
! 	 isn't an issue if the decl is not addressable.  Likewise if it
! 	 is of unknown size.
! 
! 	 Note that do_type_align may set DECL_USER_ALIGN, so we need to
! 	 check old_user_align instead.  */
        if (packed_p
! 	  && !old_user_align
! 	  && (DECL_NONADDRESSABLE_P (decl)
! 	      || DECL_SIZE_UNIT (decl) == 0
! 	      || TREE_CODE (DECL_SIZE_UNIT (decl)) == INTEGER_CST))
  	DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
  
        if (! packed_p && ! DECL_USER_ALIGN (decl))
--- 414,424 ----
        else
  	do_type_align (type, decl);
  
!       /* If the field is packed and not explicitly aligned, give it the
! 	 minimum alignment.  Note that do_type_align may set
! 	 DECL_USER_ALIGN, so we need to check old_user_align instead.  */
        if (packed_p
! 	  && !old_user_align)
  	DECL_ALIGN (decl) = MIN (DECL_ALIGN (decl), BITS_PER_UNIT);
  
        if (! packed_p && ! DECL_USER_ALIGN (decl))
Index: testsuite/gcc.dg/packed-vla.c
===================================================================
*** testsuite/gcc.dg/packed-vla.c	(revision 0)
--- testsuite/gcc.dg/packed-vla.c	(revision 0)
***************
*** 0 ****
--- 1,30 ----
+ /* { dg-do run } */
+ /* { dg-options "" } */
+ 
+ extern int printf (const char *, ...);
+ extern void abort ();
+ 
+ int func(int levels) 
+ {
+   struct bar {
+     unsigned char	a;
+     int			b[levels];
+   } __attribute__ ((__packed__)) bar;
+ 
+   struct foo {
+     unsigned char	a;
+     int			b[4];
+   } __attribute__ ((__packed__)) foo;
+ 
+   printf("foo %d\n", sizeof(foo));
+   printf("bar %d\n", sizeof(bar));
+ 
+   if (sizeof (foo) != sizeof (bar))
+     abort ();
+ }
+ 
+ int main()
+ {
+   func(4);
+   return 0;
+ }

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