[patch i386]: Set for method-functions default calling-convention to thiscall for 32-bit msabi
Kai Tietz
ktietz70@googlemail.com
Fri Apr 1 17:39:00 GMT 2011
Hello,
this patch sets for c++ methods, which are not stdarg ones, the
default calling-convention to thiscall for ms_abi 32-bit, as vendor
specific compiler does.
ChangeLog
2011-04-01 Kai Tietz
* i386.c (ix86_is_msabi_thiscall): New helper function.
(ix86_comp_type_attributes): Handle thiscall for method-functions
special.
(init_cumulative_args): Likewise.
(find_drap_reg): Likewise.
(ix86_static_chain): Likewise.
(x86_this_parameter): Likewise.
(x86_output_mi_thunk): Likewise.
Tested for i686-w64-mingw32 (some parts of the g++ testsuite are still
running). Regression tested for i686-pc-cygwin, x86_64-pc-linux-gnu.
Ok for apply?
Regards,
Kai
-------------- next part --------------
Index: gcc/gcc/config/i386/i386.c
===================================================================
--- gcc.orig/gcc/config/i386/i386.c 2011-04-01 18:26:53.207236300 +0200
+++ gcc/gcc/config/i386/i386.c 2011-04-01 19:31:25.249999000 +0200
@@ -5436,6 +5436,20 @@ ix86_handle_cconv_attribute (tree *node,
return NULL_TREE;
}
+/* This function checks if the method-function has default __thiscall
+ calling-convention for 32-bit msabi.
+ It returns true if TYPE is of kind METHOD_TYPE, no stdarg function,
+ and the MS_ABI 32-bit is used. Otherwise it returns false. */
+
+static bool
+ix86_is_msabi_thiscall (const_tree type)
+{
+ if (TARGET_64BIT || ix86_function_type_abi (type) != MS_ABI
+ || TREE_CODE (type) != METHOD_TYPE || stdarg_p (type))
+ return false;
+ return true;
+}
+
/* Return 0 if the attributes for two types are incompatible, 1 if they
are compatible, and 2 if they are nearly compatible (which causes a
warning to be generated). */
@@ -5444,7 +5458,8 @@ static int
ix86_comp_type_attributes (const_tree type1, const_tree type2)
{
/* Check for mismatch of non-default calling convention. */
- const char *const rtdstr = TARGET_RTD ? "cdecl" : "stdcall";
+ bool is_thiscall = ix86_is_msabi_thiscall (type1);
+ const char *const rtdstr = TARGET_RTD ? (is_thiscall ? "thiscall" : "cdecl") : "stdcall";
if (TREE_CODE (type1) != FUNCTION_TYPE
&& TREE_CODE (type1) != METHOD_TYPE)
@@ -5463,9 +5478,18 @@ ix86_comp_type_attributes (const_tree ty
return 0;
/* Check for mismatched thiscall types. */
- if (!lookup_attribute ("thiscall", TYPE_ATTRIBUTES (type1))
- != !lookup_attribute ("thiscall", TYPE_ATTRIBUTES (type2)))
- return 0;
+ if (is_thiscall && !TARGET_RTD)
+ {
+ if (!lookup_attribute ("cdecl", TYPE_ATTRIBUTES (type1))
+ != !lookup_attribute ("cdecl", TYPE_ATTRIBUTES (type2)))
+ return 0;
+ }
+ else if (!is_thiscall || TARGET_RTD)
+ {
+ if (!lookup_attribute ("thiscall", TYPE_ATTRIBUTES (type1))
+ != !lookup_attribute ("thiscall", TYPE_ATTRIBUTES (type2)))
+ return 0;
+ }
/* Check for mismatched return types (cdecl vs stdcall). */
if (!lookup_attribute (rtdstr, TYPE_ATTRIBUTES (type1))
@@ -5500,7 +5524,8 @@ ix86_function_regparm (const_tree type,
if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
return 2;
- if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (type)))
+ if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (type))
+ || ix86_is_msabi_thiscall (type))
return 1;
/* Use register calling convention for local functions when possible. */
@@ -5666,7 +5691,8 @@ ix86_return_pops_args (tree fundecl, tre
variable args. */
if (lookup_attribute ("stdcall", TYPE_ATTRIBUTES (funtype))
|| lookup_attribute ("fastcall", TYPE_ATTRIBUTES (funtype))
- || lookup_attribute ("thiscall", TYPE_ATTRIBUTES (funtype)))
+ || lookup_attribute ("thiscall", TYPE_ATTRIBUTES (funtype))
+ || ix86_is_msabi_thiscall (funtype))
rtd = 1;
if (rtd && ! stdarg_p (funtype))
@@ -6004,7 +6030,8 @@ init_cumulative_args (CUMULATIVE_ARGS *c
else look for regparm information. */
if (fntype)
{
- if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype)))
+ if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype))
+ || ix86_is_msabi_thiscall (fntype))
{
cum->nregs = 1;
cum->fastcall = 1; /* Same first register as in fastcall. */
@@ -9799,7 +9826,8 @@ find_drap_reg (void)
&& !lookup_attribute ("fastcall",
TYPE_ATTRIBUTES (TREE_TYPE (decl)))
&& !lookup_attribute ("thiscall",
- TYPE_ATTRIBUTES (TREE_TYPE (decl))))
+ TYPE_ATTRIBUTES (TREE_TYPE (decl)))
+ && ! ix86_is_msabi_thiscall (TREE_TYPE (decl)))
return CX_REG;
else
return DI_REG;
@@ -23249,7 +23277,8 @@ ix86_static_chain (const_tree fndecl, bo
us with EAX for the static chain. */
regno = AX_REG;
}
- else if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype)))
+ else if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype))
+ || ix86_is_msabi_thiscall (fntype))
{
/* Thiscall functions use ecx for arguments, which leaves
us with EAX for the static chain. */
@@ -29806,7 +29835,8 @@ x86_this_parameter (tree function)
if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
regno = aggr ? DX_REG : CX_REG;
- else if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (type)))
+ else if (lookup_attribute ("thiscall", TYPE_ATTRIBUTES (type))
+ || ix86_is_msabi_thiscall (type))
{
regno = CX_REG;
if (aggr)
@@ -29926,7 +29956,8 @@ x86_output_mi_thunk (FILE *file,
if (lookup_attribute ("fastcall",
TYPE_ATTRIBUTES (TREE_TYPE (function)))
|| lookup_attribute ("thiscall",
- TYPE_ATTRIBUTES (TREE_TYPE (function))))
+ TYPE_ATTRIBUTES (TREE_TYPE (function)))
+ || ix86_is_msabi_thiscall (TREE_TYPE (function)))
tmp_regno = AX_REG;
tmp = gen_rtx_REG (SImode, tmp_regno);
}
More information about the Gcc-patches
mailing list