From 13c1cd82670b0be75bf99ba5bd23a7c34460fe65 Mon Sep 17 00:00:00 2001 From: Paul Brook Date: Fri, 14 May 2004 12:53:11 +0000 Subject: [PATCH] stor-layout.c (update_alignment_for_field): Use targetm.align_anon_bitfield. * 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. From-SVN: r81838 --- gcc/ChangeLog | 11 +++++++++++ gcc/config/arm/arm.c | 13 +++++++++++++ gcc/doc/tm.texi | 7 +++++++ gcc/stor-layout.c | 6 ++++-- gcc/target-def.h | 2 ++ gcc/target.h | 3 +++ 6 files changed, 40 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 66e9db272ed..968a23f9336 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,14 @@ +2004-05-14 Paul Brook + + * 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. + 2004-05-13 Zack Weinberg * tree.def (documentation): Remove mention of class 'b'. diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c index 7cf835ce918..acbdb77f15b 100644 --- a/gcc/config/arm/arm.c +++ b/gcc/config/arm/arm.c @@ -160,6 +160,7 @@ static void arm_setup_incoming_varargs (CUMULATIVE_ARGS *, enum machine_mode, tree, int *, int); static bool arm_promote_prototypes (tree); static bool arm_default_short_enums (void); +static bool arm_align_anon_bitfield (void); /* Initialize the GCC target structure. */ @@ -260,6 +261,9 @@ static bool arm_default_short_enums (void); #undef TARGET_DEFAULT_SHORT_ENUMS #define TARGET_DEFAULT_SHORT_ENUMS arm_default_short_enums +#undef TARGET_ALIGN_ANON_BITFIELD +#define TARGET_ALIGN_ANON_BITFIELD arm_align_anon_bitfield + struct gcc_target targetm = TARGET_INITIALIZER; /* Obstack for minipool constant handling. */ @@ -14565,3 +14569,12 @@ arm_default_short_enums (void) { return TARGET_AAPCS_BASED; } + + +/* AAPCS requires that anonymous bitfields affect structure alignment. */ + +static bool +arm_align_anon_bitfield (void) +{ + return TARGET_AAPCS_BASED; +} diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 339dc7ad1c4..a0f855d904e 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -1301,6 +1301,13 @@ Like @code{PCC_BITFIELD_TYPE_MATTERS} except that its effect is limited to aligning a bit-field within the structure. @end defmac +@deftypefn {Target Hook} bool TARGET_ALIGN_ANON_BITFIELDS (void) +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. +@end deftypefn + @defmac MEMBER_TYPE_FORCES_BLK (@var{field}, @var{mode}) Return 1 if a structure or array containing @var{field} should be accessed using @code{BLKMODE}. diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 13f95a44ff5..5c87a638376 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -771,8 +771,10 @@ update_alignment_for_field (record_layout_info rli, tree field, else if (is_bitfield && PCC_BITFIELD_TYPE_MATTERS) { /* Named bit-fields cause the entire structure to have the - alignment implied by their type. */ - if (DECL_NAME (field) != 0) + alignment implied by their type. Some targets also apply the same + rules to unnamed bitfields. */ + if (DECL_NAME (field) != 0 + || targetm.align_anon_bitfield ()) { unsigned int type_align = TYPE_ALIGN (type); diff --git a/gcc/target-def.h b/gcc/target-def.h index 62060abebf2..f8c832a251e 100644 --- a/gcc/target-def.h +++ b/gcc/target-def.h @@ -310,6 +310,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define TARGET_INSERT_ATTRIBUTES hook_void_tree_treeptr #define TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P hook_bool_tree_false #define TARGET_MS_BITFIELD_LAYOUT_P hook_bool_tree_false +#define TARGET_ALIGN_ANON_BITFIELD hook_bool_void_false #define TARGET_RTX_COSTS hook_bool_rtx_int_int_intp_false #define TARGET_MANGLE_FUNDAMENTAL_TYPE hook_constcharptr_tree_null @@ -384,6 +385,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. TARGET_INSERT_ATTRIBUTES, \ TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P, \ TARGET_MS_BITFIELD_LAYOUT_P, \ + TARGET_ALIGN_ANON_BITFIELD, \ TARGET_INIT_BUILTINS, \ TARGET_EXPAND_BUILTIN, \ TARGET_MANGLE_FUNDAMENTAL_TYPE, \ diff --git a/gcc/target.h b/gcc/target.h index c122adbcdfa..6e288104559 100644 --- a/gcc/target.h +++ b/gcc/target.h @@ -307,6 +307,9 @@ struct gcc_target Microsoft Visual C++ bitfield layout rules. */ bool (* ms_bitfield_layout_p) (tree record_type); + /* Return true if anonymous bitfields affect structure alignment. */ + bool (* align_anon_bitfield) (void); + /* Set up target-specific built-in functions. */ void (* init_builtins) (void); -- 2.30.2