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,arm] Alignment of anonymous bitfields


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.

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.  */
-      if (DECL_NAME (field) != 0)
+      if (DECL_NAME (field) != 0
+	  || targetm.align_anon_bitfield ())
 	{
 	  unsigned int type_align = TYPE_ALIGN (type);
 
Index: target-def.h
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/target-def.h,v
retrieving revision 1.77
diff -u -p -r1.77 target-def.h
--- a/target-def.h	24 Mar 2004 00:13:20 -0000	1.77
+++ b/target-def.h	13 May 2004 17:23:51 -0000
@@ -310,6 +310,7 @@ Foundation, 59 Temple Place - Suite 330,
 #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,
   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,		\
Index: target.h
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/target.h,v
retrieving revision 1.85
diff -u -p -r1.85 target.h
--- a/target.h	24 Mar 2004 00:13:20 -0000	1.85
+++ b/target.h	13 May 2004 17:23:51 -0000
@@ -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);
 
Index: config/arm/arm.c
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/config/arm/arm.c,v
retrieving revision 1.360
diff -u -p -r1.360 arm.c
--- a/config/arm/arm.c	13 May 2004 11:16:27 -0000	1.360
+++ b/config/arm/arm.c	13 May 2004 17:23:51 -0000
@@ -160,6 +160,7 @@ static void arm_setup_incoming_varargs (
 					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 (voi
 #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 the anonymos bitfields affect structure alignment.  */
+
+static bool
+arm_align_anon_bitfield (void)
+{
+  return TARGET_AAPCS_BASED;
+}
Index: doc/tm.texi
===================================================================
RCS file: /var/cvsroot/gcc-cvs/gcc/gcc/doc/tm.texi,v
retrieving revision 1.322
diff -u -p -r1.322 tm.texi
--- a/doc/tm.texi	13 May 2004 06:40:27 -0000	1.322
+++ b/doc/tm.texi	13 May 2004 17:59:01 -0000
@@ -1301,6 +1301,12 @@ Like @code{PCC_BITFIELD_TYPE_MATTERS} ex
 to aligning a bit-field within the structure.
 @end defmac
 
+@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
+
 @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}.


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