diff mbox

[i386] Fix PR66275 __attribute__((sysv_abi)) with x86_64-w64-mingw32-gcc generates incorrect code

Message ID CAFULd4YsBqhS4nbr4yohSPXzLNbYVLqqKHKvNc1HCeCWmO=sqg@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak June 3, 2015, 3:50 p.m. UTC
Hello!

As explained in the PR, we have to consider attribute that switches
target ABI also for  ix86_function_arg_regno_p and
ix86_function_value_regno_p.

2015-06-03  Uros Bizjak  <ubizjak@gmail.com>

    PR target/66275
    * config/i386/i386.c (ix86_function_arg_regno): Use ix86_cfun_abi
    to determine current function ABI.
    (ix86_function_value_regno_p): Ditto.

testsuite/ChangeLog:

2015-06-03  Uros Bizjak  <ubizjak@gmail.com>

    PR target/66275
    * gcc.target/i386/pr66275.c: New test.

Bootstrapped on x86_64-linux-gnu and by Kai on x86_64-w64-mingw32.

Committed to mainline SVN, will be committed to release branches in a week.

Uros.
diff mbox

Patch

Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 223995)
+++ config/i386/i386.c	(working copy)
@@ -6149,6 +6149,7 @@  bool
 ix86_function_arg_regno_p (int regno)
 {
   int i;
+  enum calling_abi call_abi;
   const int *parm_regs;
 
   if (TARGET_MPX && BND_REGNO_P (regno))
@@ -6174,16 +6175,18 @@  ix86_function_arg_regno_p (int regno)
   /* TODO: The function should depend on current function ABI but
      builtins.c would need updating then. Therefore we use the
      default ABI.  */
+  call_abi = ix86_cfun_abi ();
 
   /* RAX is used as hidden argument to va_arg functions.  */
-  if (ix86_abi == SYSV_ABI && regno == AX_REG)
+  if (call_abi == SYSV_ABI && regno == AX_REG)
     return true;
 
-  if (ix86_abi == MS_ABI)
+  if (call_abi == MS_ABI)
     parm_regs = x86_64_ms_abi_int_parameter_registers;
   else
     parm_regs = x86_64_int_parameter_registers;
-  for (i = 0; i < (ix86_abi == MS_ABI
+
+  for (i = 0; i < (call_abi == MS_ABI
 		   ? X86_64_MS_REGPARM_MAX : X86_64_REGPARM_MAX); i++)
     if (regno == parm_regs[i])
       return true;
@@ -8212,10 +8215,10 @@  ix86_function_value_regno_p (const unsigned int re
     case AX_REG:
       return true;
     case DX_REG:
-      return (!TARGET_64BIT || ix86_abi != MS_ABI);
+      return (!TARGET_64BIT || ix86_cfun_abi () != MS_ABI);
     case DI_REG:
     case SI_REG:
-      return TARGET_64BIT && ix86_abi != MS_ABI;
+      return TARGET_64BIT && ix86_cfun_abi () != MS_ABI;
 
     case BND0_REG:
     case BND1_REG:
@@ -8227,7 +8230,7 @@  ix86_function_value_regno_p (const unsigned int re
       /* TODO: The function should depend on current function ABI but
        builtins.c would need updating then. Therefore we use the
        default ABI.  */
-      if (TARGET_64BIT && ix86_abi == MS_ABI)
+      if (TARGET_64BIT && ix86_cfun_abi () == MS_ABI)
 	return false;
       return TARGET_FLOAT_RETURNS_IN_80387;
 
Index: testsuite/gcc.target/i386/pr66275.c
===================================================================
--- testsuite/gcc.target/i386/pr66275.c	(revision 0)
+++ testsuite/gcc.target/i386/pr66275.c	(working copy)
@@ -0,0 +1,8 @@ 
+/* { dg-do compile { target { *-*-linux* && { ! ia32 } } } } */
+/* { dg-options "-mabi=ms -fdump-rtl-dfinit" } */
+
+void
+__attribute__((sysv_abi))
+foo () {};
+
+/* { dg-final { scan-rtl-dump "entry block defs\[^\\n]*\\\[si\\]\[^\\n]*\\\[di\\]" "dfinit" } } */