From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5813 invoked by alias); 28 Nov 2012 18:53:07 -0000 Received: (qmail 5796 invoked by uid 22791); 28 Nov 2012 18:53:05 -0000 X-SWARE-Spam-Status: No, hits=-3.8 required=5.0 tests=AWL,BAYES_00,DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE,TW_FN X-Spam-Check-By: sourceware.org Received: from mail-ea0-f175.google.com (HELO mail-ea0-f175.google.com) (209.85.215.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 28 Nov 2012 18:52:59 +0000 Received: by mail-ea0-f175.google.com with SMTP id h11so5719271eaa.20 for ; Wed, 28 Nov 2012 10:52:58 -0800 (PST) MIME-Version: 1.0 Received: by 10.14.2.196 with SMTP id 44mr44077292eef.25.1354128778059; Wed, 28 Nov 2012 10:52:58 -0800 (PST) Received: by 10.14.174.7 with HTTP; Wed, 28 Nov 2012 10:52:57 -0800 (PST) In-Reply-To: <50B658DC.9020802@redhat.com> References: <50B63460.7000902@redhat.com> <50B658DC.9020802@redhat.com> Date: Wed, 28 Nov 2012 18:53:00 -0000 Message-ID: Subject: Re: [patch i386} Fix PR 55171 - [4.7/4.8 Regression] incorrect virtual thunk on mingw From: Kai Tietz To: Richard Henderson Cc: GCC Patches Content-Type: text/plain; charset=ISO-8859-1 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-11/txt/msg02359.txt.bz2 Fine. Here is a adjusted version which keeps old abi behavior for chain-registers. 2012-11-28 Kai Tietz PR target/55171 * i386.c (get_scratch_register_on_entry): Handle thiscall-convention. (split_stack_prologue_scratch_regno): Likewise. (ix86_static_chain): Likewise. (x86_output_mi_thunk): Likewise. Test on i686-w64-mingw32. Ok for apply? Regards, Kai Index: i386.c =================================================================== --- i386.c (Revision 193781) +++ i386.c (Arbeitskopie) @@ -9655,6 +9655,8 @@ tree decl = current_function_decl, fntype = TREE_TYPE (decl); bool fastcall_p = lookup_attribute ("fastcall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE; + bool thiscall_p + = lookup_attribute ("thiscall", TYPE_ATTRIBUTES (fntype)) != NULL_TREE; bool static_chain_p = DECL_STATIC_CHAIN (decl); int regparm = ix86_function_regparm (fntype, decl); int drap_regno @@ -9665,10 +9667,15 @@ if ((regparm < 1 || (fastcall_p && !static_chain_p)) && drap_regno != AX_REG) regno = AX_REG; - else if (regparm < 2 && drap_regno != DX_REG) + /* 'thiscall' sets regparm to 1, uses ecx for arguments and edx + for the static chain register. */ + else if (thiscall_p && !static_chain_p && drap_regno != AX_REG) + regno = AX_REG; + else if (regparm < 2 && !thiscall_p && drap_regno != DX_REG) regno = DX_REG; /* ecx is the static chain register. */ - else if (regparm < 3 && !fastcall_p && !static_chain_p + else if (regparm < 3 && !fastcall_p && !thiscall_p + && !static_chain_p && drap_regno != CX_REG) regno = CX_REG; else if (ix86_save_reg (BX_REG, true)) @@ -11180,12 +11187,15 @@ return R11_REG; else { - bool is_fastcall; + bool is_fastcall, is_thiscall; int regparm; is_fastcall = (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl))) != NULL); + is_thiscall = (lookup_attribute ("thiscall", + TYPE_ATTRIBUTES (TREE_TYPE (cfun->decl))) + != NULL); regparm = ix86_function_regparm (TREE_TYPE (cfun->decl), cfun->decl); if (is_fastcall) @@ -11198,6 +11208,12 @@ } return AX_REG; } + else if (is_thiscall) + { + if (!DECL_STATIC_CHAIN (cfun->decl)) + return DX_REG; + return AX_REG; + } else if (regparm < 3) { if (!DECL_STATIC_CHAIN (cfun->decl)) @@ -25134,7 +25150,7 @@ fntype = TREE_TYPE (fndecl); ccvt = ix86_get_callcvt (fntype); - if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) != 0) + if ((ccvt & IX86_CALLCVT_FASTCALL) != 0) { /* Fastcall functions use ecx/edx for arguments, which leaves us with EAX for the static chain. @@ -25142,6 +25158,13 @@ leaves us with EAX for the static chain. */ regno = AX_REG; } + else if ((ccvt & IX86_CALLCVT_THISCALL) != 0) + { + /* Thiscall functions use ecx for arguments, which leaves + us with EAX and EDX for the static chain. + We are using for abi-compatibility EAX. */ + regno = AX_REG; + } else if (ix86_function_regparm (fntype, fndecl) == 3) { /* For regparm 3, we have no free call-clobbered registers in @@ -34799,8 +34822,10 @@ else { unsigned int ccvt = ix86_get_callcvt (TREE_TYPE (function)); - if ((ccvt & (IX86_CALLCVT_FASTCALL | IX86_CALLCVT_THISCALL)) != 0) + if ((ccvt & IX86_CALLCVT_FASTCALL) != 0) tmp_regno = AX_REG; + else if ((ccvt & IX86_CALLCVT_THISCALL) != 0) + tmp_regno = DX_REG; else tmp_regno = CX_REG; }