PATCH: Enable __declspec(align(N)) for x86

H. J. Lu hjl@lucon.org
Tue Apr 3 16:27:00 GMT 2007


On Mon, Apr 02, 2007 at 03:41:29PM -0700, H. J. Lu wrote:
> On Mon, Apr 02, 2007 at 03:35:01PM -0700, Mike Stump wrote:
> > On Apr 2, 2007, at 3:18 PM, H. J. Lu wrote:
> > >-    builtin_define ("__declspec(x)=__attribute__((x))");
> > >+    {
> > >+      builtin_define ("align(x)=aligned((x))");
> > 
> > On second thought...  I don't want this, too dangerous..  better to  
> > have align accepted in an attribute.
> 

We can't include "c-common.h" in config/i386/i386.c since not
all frontends are linked with c-common.o.  This patch adds
TARGET_ALIGN_DECL_ATTRIBUTES so that we can add align(N) to
c-common.o.


H.J.
----
2007-04-03  H.J. Lu  <hongjiu.lu@intel.com>

	* c-common.c (c_common_attribute_table): Add align if
	TARGET_ALIGN_DECL_ATTRIBUTES isn't 0.

	* config/i386/beos-elf.h (TARGET_DECLSPEC): Removed.
	* config/i386/i386-interix.h (TARGET_DECLSPEC): Likewise.

	* config/i386/i386.h (TARGET_ALIGN_DECL_ATTRIBUTES): Define as
	1 if not defined.

	* defaults.h (TARGET_ALIGN_DECL_ATTRIBUTES): Define as 0 if not
	defined.
	(TARGET_DECLSPEC): Define as 1 if not defined and
	TARGET_ALIGN_DECL_ATTRIBUTES isn't 0.

	* doc/extend.texi: Document align.

	* doc/tm.texi: Document TARGET_ALIGN_DECL_ATTRIBUTES.

--- gcc/c-common.c.decl	2007-03-19 15:03:01.000000000 -0700
+++ gcc/c-common.c	2007-04-03 08:44:42.000000000 -0700
@@ -611,6 +611,10 @@ const struct attribute_spec c_common_att
 			      handle_section_attribute },
   { "aligned",                0, 1, false, false, false,
 			      handle_aligned_attribute },
+#if TARGET_ALIGN_DECL_ATTRIBUTES
+  { "align",                  0, 1, false, false, false,
+			      handle_aligned_attribute },
+#endif
   { "weak",                   0, 0, true,  false, false,
 			      handle_weak_attribute },
   { "alias",                  1, 1, true,  false, false,
--- gcc/config/i386/beos-elf.h.decl	2006-12-14 09:01:23.000000000 -0800
+++ gcc/config/i386/beos-elf.h	2007-04-03 08:42:36.000000000 -0700
@@ -56,8 +56,6 @@ Boston, MA 02110-1301, USA.  */
 #undef WCHAR_TYPE_SIZE
 #define WCHAR_TYPE_SIZE 16
 
-#define TARGET_DECLSPEC 1
-
 #define TARGET_OS_CPP_BUILTINS()					\
   do									\
     {									\
--- gcc/config/i386/i386-interix.h.decl	2007-03-30 17:36:04.000000000 -0700
+++ gcc/config/i386/i386-interix.h	2007-04-03 08:42:36.000000000 -0700
@@ -54,8 +54,6 @@ Boston, MA 02110-1301, USA.  */
 
 #define ASM_LOAD_ADDR(loc, reg)   "     leal " #loc "," #reg "\n"
 
-#define TARGET_DECLSPEC 1
-
 /* cpp handles __STDC__ */
 #define TARGET_OS_CPP_BUILTINS()					\
   do									\
--- gcc/config/i386/i386.h.decl	2007-04-02 10:42:32.000000000 -0700
+++ gcc/config/i386/i386.h	2007-04-03 08:46:58.000000000 -0700
@@ -2419,6 +2419,11 @@ struct machine_function GTY(())
 #define SYMBOL_REF_DLLEXPORT_P(X) \
 	((SYMBOL_REF_FLAGS (X) & SYMBOL_FLAG_DLLEXPORT) != 0)
 
+/* Enable __declspec(align(16)) by default.  */
+#ifndef TARGET_ALIGN_DECL_ATTRIBUTES
+#define TARGET_ALIGN_DECL_ATTRIBUTES 1
+#endif
+
 /*
 Local variables:
 version-control: t
--- gcc/defaults.h.decl	2007-03-24 11:57:26.000000000 -0700
+++ gcc/defaults.h	2007-04-03 09:20:45.000000000 -0700
@@ -468,8 +468,12 @@ Software Foundation, 51 Franklin Street,
 #define TARGET_DLLIMPORT_DECL_ATTRIBUTES 0
 #endif
 
+#ifndef TARGET_ALIGN_DECL_ATTRIBUTES
+#define TARGET_ALIGN_DECL_ATTRIBUTES 0
+#endif
+
 #ifndef TARGET_DECLSPEC
-#if TARGET_DLLIMPORT_DECL_ATTRIBUTES
+#if TARGET_DLLIMPORT_DECL_ATTRIBUTES || TARGET_ALIGN_DECL_ATTRIBUTES
 /* If the target supports the "dllimport" attribute, users are
    probably used to the "__declspec" syntax.  */
 #define TARGET_DECLSPEC 1
--- gcc/doc/extend.texi.decl	2007-03-30 17:35:50.000000000 -0700
+++ gcc/doc/extend.texi	2007-04-03 09:17:24.000000000 -0700
@@ -3093,6 +3093,11 @@ up to a maximum of 8 byte alignment, the
 in an @code{__attribute__} will still only provide you with 8 byte
 alignment.  See your linker documentation for further information.
 
+@cindex @code{align} attribute
+@item align (@var{alignment})
+Some targets, e.g. i386, support the @code{align} attribute, which
+is an alias of @code{aligned}.
+
 @item cleanup (@var{cleanup_function})
 @cindex @code{cleanup} attribute
 The @code{cleanup} attribute runs a function when the variable goes
@@ -3349,12 +3354,14 @@ addresses).
 @anchor{i386 Variable Attributes}
 @subsection i386 Variable Attributes
 
-Two attributes are currently defined for i386 configurations:
-@code{ms_struct} and @code{gcc_struct}
+Three attributes are currently defined for i386 configurations:
+@code{align}, @code{ms_struct} and @code{gcc_struct}
 
 @table @code
-@item ms_struct
+@item align
+@itemx ms_struct
 @itemx gcc_struct
+@cindex @code{align} attribute
 @cindex @code{ms_struct} attribute
 @cindex @code{gcc_struct} attribute
 
@@ -3829,11 +3836,13 @@ most Symbian OS code uses @code{__declsp
 @anchor{i386 Type Attributes}
 @subsection i386 Type Attributes
 
-Two attributes are currently defined for i386 configurations:
-@code{ms_struct} and @code{gcc_struct}
+Three attributes are currently defined for i386 configurations:
+@code{align}, @code{ms_struct} and @code{gcc_struct}
 
-@item ms_struct
+@item align
+@itemx ms_struct
 @itemx gcc_struct
+@cindex @code{align}
 @cindex @code{ms_struct}
 @cindex @code{gcc_struct}
 
--- gcc/doc/tm.texi.decl	2007-04-02 06:39:26.000000000 -0700
+++ gcc/doc/tm.texi	2007-04-03 09:13:30.000000000 -0700
@@ -9011,6 +9011,12 @@ of @code{__declspec} is via a built-in m
 on this implementation detail.
 @end defmac
 
+@findex TARGET_ALIGN_DECL_ATTRIBUTES
+If the target-specific handling requires @code{__declspec(align(N))},
+you should define the macro @code{TARGET_ALIGN_DECL_ATTRIBUTES} to
+@code{1}.  The compiler will then define @code{TARGET_DECLSPEC} to
+@code{1} and enable @code{align} as an alias of @code{aligned}.
+
 @deftypefn {Target Hook} void TARGET_INSERT_ATTRIBUTES (tree @var{node}, tree *@var{attr_ptr})
 Define this target hook if you want to be able to add attributes to a decl
 when it is being created.  This is normally useful for back ends which



More information about the Gcc-patches mailing list