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 to layout_decl for 11446


THIS PATCH FIXES AN ABI COMPATIBILITY BUG BETWEEN THE TRUNK AND PREVIOUS
RELEASES.

PR 11446 is a conflict between packed and aligned attributes.  In earlier
releases, declaring a struct as packed overrides aligned attributes on the
types of fields, but does not override aligned attributes directly on the
fields.  My reworking of the field layout code changed that rule; this
patch restores it.

Test in gcc.dg/pack-test-5.c.  Tested x86_64-pc-linux-gnu, applied to trunk.

2003-10-20  Jason Merrill  <jason@redhat.com>

	PR c/11446
	* stor-layout.c (layout_decl): Fix alignment handling.

*** stor-layout.c.~1~	2003-10-13 15:23:04.000000000 -0400
--- stor-layout.c	2003-10-17 14:40:23.000000000 -0400
*************** layout_decl (tree decl, unsigned int kno
*** 450,469 ****
  	}
        else if (DECL_PACKED (decl) && DECL_USER_ALIGN (decl))
  	/* Don't touch DECL_ALIGN.  For other packed fields, go ahead and
! 	   round up; we'll reduce it again below.  */;
        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.  */
!       if (DECL_PACKED (decl)
! 	  && !DECL_USER_ALIGN (decl)
! 	  && (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);
  
        /* Should this be controlled by DECL_USER_ALIGN, too?  */
        if (maximum_field_alignment != 0)
--- 450,475 ----
  	}
        else if (DECL_PACKED (decl) && DECL_USER_ALIGN (decl))
  	/* Don't touch DECL_ALIGN.  For other packed fields, go ahead and
! 	   round up; we'll reduce it again below.  We want packing to
! 	   supercede USER_ALIGN inherited from the type, but defer to
! 	   alignment explicitly specified on the field decl.  */;
        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 don't
! 	     want to check it again here.  */
! 	  if (DECL_PACKED (decl)
! 	      && (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);
! 	}
  
        /* Should this be controlled by DECL_USER_ALIGN, too?  */
        if (maximum_field_alignment != 0)

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