diff mbox

[i386] : Allow attribute ms_abi/sysv_abi for 32-bit

Message ID 1214771522.287167.1311757965731.JavaMail.root@zmail06.collab.prod.int.phx2.redhat.com
State New
Headers show

Commit Message

Kai Tietz July 27, 2011, 9:12 a.m. UTC
Hello,

this patch allows the function attributes sysv_abi/ms_abi also for 32-bit.  Additionally it allows the switch -mabi for 32-bit i386 targets, too.
This patch completes the GNU/MS abi switching support for 32-bit.  Main difference for 32-bit is the caller/callee pops hidden aggregate pointer default.


ChangeLog

2011-07-27  Kai Tietz  <ktietz@redhat.com>

        * config/i386/i386.c (ix86_option_override_internal): Allow -mabi
        for 32-bit, too.
        (ix86_handle_abi_attribute): Allow function attributes ms_abi/sysv_abi
        in 32-bit mode, too.
        * doc/extend.texi: Adjust attribute documentation.

2011-07-27  Kai Tietz  <ktietz@redhat.com>

        * gcc.target/i386/aggregate-ret3.c: New test.
        * gcc.target/i386/aggregate-ret4.c: New test.

Bootstrapped and regression-tested on x86_64-pc-linux-gnu (multilib), and i686-w64-mingw32.
Ok for apply?

Regards,
Kai

Comments

Richard Henderson July 27, 2011, 3:13 p.m. UTC | #1
On 07/27/2011 02:12 AM, Kai Tietz wrote:
> 2011-07-27  Kai Tietz  <ktietz@redhat.com>
> 
>         * config/i386/i386.c (ix86_option_override_internal): Allow -mabi
>         for 32-bit, too.
>         (ix86_handle_abi_attribute): Allow function attributes ms_abi/sysv_abi
>         in 32-bit mode, too.
>         * doc/extend.texi: Adjust attribute documentation.
> 
> 2011-07-27  Kai Tietz  <ktietz@redhat.com>
> 
>         * gcc.target/i386/aggregate-ret3.c: New test.
>         * gcc.target/i386/aggregate-ret4.c: New test.

Ok.


r~
diff mbox

Patch

Index: gcc-head/gcc/config/i386/i386.c
===================================================================
--- gcc-head.orig/gcc/config/i386/i386.c
+++ gcc-head/gcc/config/i386/i386.c
@@ -3133,9 +3133,6 @@  ix86_option_override_internal (bool main
   if (!global_options_set.x_ix86_abi)
     ix86_abi = DEFAULT_ABI;
 
-  if (ix86_abi == MS_ABI && TARGET_X32)
-    error ("MS ABI not supported in x32 mode");
-
   if (global_options_set.x_ix86_cmodel)
     {
       switch (ix86_cmodel)
@@ -29325,13 +29322,6 @@  ix86_handle_abi_attribute (tree *node, t
       *no_add_attrs = true;
       return NULL_TREE;
     }
-  if (!TARGET_LP64)
-    {
-      warning (OPT_Wattributes, "%qE attribute only available for 64-bit",
-	       name);
-      *no_add_attrs = true;
-      return NULL_TREE;
-    }
 
   /* Can combine regparm with all attributes but fastcall.  */
   if (is_attribute_p ("ms_abi", name))
Index: gcc-head/gcc/testsuite/gcc.target/i386/aggregate-ret3.c
===================================================================
--- /dev/null
+++ gcc-head/gcc/testsuite/gcc.target/i386/aggregate-ret3.c
@@ -0,0 +1,28 @@ 
+/* Check that, with keep_aggregate_return_pointer attribute,  callee does
+   not pop the stack for the implicit pointer arg when returning a large
+   structure in memory.  */
+/* { dg-do compile } */
+/* { dg-require-effective-target ia32 } */
+
+struct foo {
+  int a;
+  int b;
+  int c;
+  int d;
+};
+
+__attribute__ ((ms_abi))
+struct foo
+bar (void)
+{
+  struct foo retval;
+  retval.a = 1;
+  retval.b = 2;
+  retval.c = 3;
+  retval.d = 4;
+  return retval;
+}
+
+/* { dg-final { scan-assembler-not "ret\[ \t\]\\\$4" } } */
+
+
Index: gcc-head/gcc/testsuite/gcc.target/i386/aggregate-ret4.c
===================================================================
--- /dev/null
+++ gcc-head/gcc/testsuite/gcc.target/i386/aggregate-ret4.c
@@ -0,0 +1,28 @@ 
+/* Check that, with dont_keep_aggregate_return_pointer attribute,  callee
+   pops the stack for the implicit pointer arg when returning a large
+   structure in memory.  */
+/* { dg-do compile } */
+/* { dg-require-effective-target ia32 } */
+
+struct foo {
+  int a;
+  int b;
+  int c;
+  int d;
+};
+
+__attribute__ ((sysv_abi))
+struct foo
+bar (void)
+{
+  struct foo retval;
+  retval.a = 1;
+  retval.b = 2;
+  retval.c = 3;
+  retval.d = 4;
+  return retval;
+}
+
+/* { dg-final { scan-assembler "ret\[ \t\]\\\$4" } } */
+
+
Index: gcc-head/gcc/doc/extend.texi
===================================================================
--- gcc-head.orig/gcc/doc/extend.texi
+++ gcc-head/gcc/doc/extend.texi
@@ -2819,15 +2819,15 @@  defined by shared libraries.
 @cindex @code{ms_abi} attribute
 @cindex @code{sysv_abi} attribute
 
-On 64-bit x86_64-*-* targets, you can use an ABI attribute to indicate
-which calling convention should be used for a function.  The @code{ms_abi}
-attribute tells the compiler to use the Microsoft ABI, while the
-@code{sysv_abi} attribute tells the compiler to use the ABI used on
-GNU/Linux and other systems.  The default is to use the Microsoft ABI
-when targeting Windows.  On all other systems, the default is the AMD ABI.
+On 32-bit and 64-bit (i?86|x86_64)-*-* targets, you can use an ABI attribute
+to indicate which calling convention should be used for a function.  The
+@code{ms_abi} attribute tells the compiler to use the Microsoft ABI,
+while the @code{sysv_abi} attribute tells the compiler to use the ABI
+used on GNU/Linux and other systems.  The default is to use the Microsoft ABI
+when targeting Windows.  On all other systems, the default is the x86/AMD ABI.
 
-Note, the @code{ms_abi} attribute for Windows targets currently requires
-the @option{-maccumulate-outgoing-args} option.
+Note, the @code{ms_abi} attribute for Windows 64-bit targets currently
+requires the @option{-maccumulate-outgoing-args} option.
 
 @item callee_pop_aggregate_return (@var{number})
 @cindex @code{callee_pop_aggregate_return} attribute
@@ -2839,6 +2839,9 @@  zero -, or if the callee is responsible 
 equal to one.  The default i386 ABI assumes that the callee pops the
 stack for hidden pointer.
 
+Note, that on 32-bit i386 Windows targets the compiler assumes that the
+caller pops the stack for hidden pointer.
+
 @item ms_hook_prologue
 @cindex @code{ms_hook_prologue} attribute