[patch,arm] Alignment of anonymous bitfields

Richard Earnshaw rearnsha@arm.com
Fri May 14 10:11:00 GMT 2004


On Thu, 2004-05-13 at 20:35, Paul Brook wrote:
> The patch below adds (and uses) a target hook that makes anonymous bitfields 
> affect structure alignment in the same way as named bitfields.
> 
> Tested with cross to arm-none-elf.
> Ok?
> 
> Paul
> 
> 2004-05-13  Paul Brook  <paul@codesourcery.com>
> 
> 	* stor-layout.c (update_alignment_for_field): Use
> 	targetm.align_anon_bitfield.
> 	* target-def.h (TARGET_ALIGN_ANON_BITFIELD): Define.
> 	(TARGET_INITIALIZER): Use it.
> 	* target.h (struct gcc_target): Add align_anon_bitfield.
> 	* config/arm/arm.c (arm_align_anon_bitfield):  New function.
> 	(TARGET_ALIGN_ANON_BITFIELD): Define.
> 	* doc/tm.texi: Document TARGET_ALIGN_ANON_BITFIELD.
> 

This OK with a couple of minor tweaks.

> Index: stor-layout.c
> ===================================================================
> RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/stor-layout.c,v
> retrieving revision 1.188
> diff -u -p -r1.188 stor-layout.c
> --- a/stor-layout.c	13 May 2004 06:39:45 -0000	1.188
> +++ b/stor-layout.c	13 May 2004 17:23:51 -0000
> @@ -772,7 +772,8 @@ update_alignment_for_field (record_layou
>      {
>        /* Named bit-fields cause the entire structure to have the
>  	 alignment implied by their type.  */

Comment really needs updating.


> +/* AAPCS requires the anonymos bitfields affect structure alignment.  */
> +

Requires *that*.


> +@deftypefn {Target Hook} bool TARGET_ALIGN_ANON_BITFIELDS (void)
> +This target hook should return a nonzero value if anonymous bitfields should
> +affect structure alignment in the same way as named bitfields.  This hook
> +only takes effect when @code{PCC_BITFIELS_TYPE_MATTERS} evaluates to true.
> +@end deftypefn

Typo in PCC_BITFIEL***D***_TYPE_MATTERS.  Note that the C++ standard
talks of unnamed (rather than anonymous) bitfields.  I wonder if the
wording might be better as:

When @code{PCC_BITFIELD_TYPE_MATTERS} is true this hook will determine
whether unnamed bitfields affect the alignment of the containing
structure.  The hook should return true if the structure should inherit
the alignment requirements of an unnamed bitfield's type.

R.



More information about the Gcc-patches mailing list