From patchwork Sun Nov 25 15:26:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Tietz X-Patchwork-Id: 201547 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 45E852C008A for ; Mon, 26 Nov 2012 02:26:16 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1354461976; h=Comment: DomainKey-Signature:Received:Received:Received:Received: MIME-Version:Received:Received:Date:Message-ID:Subject:From:To: Cc:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=6atZtex NYmTNULSQbmM94/7/kF4=; b=YFXh7WHOhqxJnG7S67yPkmcs9y4j6MKWP91b62C fcNuFeFlCGbG2xMX4tLTYy1P/kn0ka8UCTWb//X69GrITf75l6eG8JBcX6FseC87 51e7IkGLVD5ArRrJKjI9E2LYZiSD+wPr3fQQRMdI6xZ7ppxUbUq4tt7fqCc2nHRm e8Wk= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:MIME-Version:Received:Received:Date:Message-ID:Subject:From:To:Cc:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=RaXlhzSnHhoKmX3T80Y3KHFaOVRRel5hnU/HJWnqbk4zW6CIBbJVHN/JCSg6U3 r26JfHRUOzLvtsYz1zlzIv+ntPJbXczu2aN3Ze0vCrCH7gQpyjhgbEsnfFk9VVdK cbZloJoVSawuqWDOlHHTBL99fNZ36SoMNS3WAiky2nGw8=; Received: (qmail 20263 invoked by alias); 25 Nov 2012 15:26:13 -0000 Received: (qmail 20250 invoked by uid 22791); 25 Nov 2012 15:26:12 -0000 X-SWARE-Spam-Status: No, hits=-3.1 required=5.0 tests=AWL, BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, KHOP_RCVD_TRUST, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, TW_FN X-Spam-Check-By: sourceware.org Received: from mail-wi0-f175.google.com (HELO mail-wi0-f175.google.com) (209.85.212.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 25 Nov 2012 15:26:07 +0000 Received: by mail-wi0-f175.google.com with SMTP id hm11so2151497wib.8 for ; Sun, 25 Nov 2012 07:26:05 -0800 (PST) MIME-Version: 1.0 Received: by 10.180.83.132 with SMTP id q4mr4256418wiy.9.1353857165015; Sun, 25 Nov 2012 07:26:05 -0800 (PST) Received: by 10.216.153.132 with HTTP; Sun, 25 Nov 2012 07:26:04 -0800 (PST) Date: Sun, 25 Nov 2012 16:26:04 +0100 Message-ID: Subject: [patch i386} Fix PR 55171 - [4.7/4.8 Regression] incorrect virtual thunk on mingw From: Kai Tietz To: GCC Patches Cc: Richard Henderson X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, the following patch adjusts used registers for thiscall-calling convention thunks, so that there aren't register-collisions. Issue was that thiscall-convention has different register-usage as regparam, but it wasn't handled. ChangeLog 2012-11-25 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 --- i386.c 2012-11-24 21:34:57.686148400 +0100 +++ i386.c2 2012-11-24 21:34:42.370272400 +0100 @@ -9655,6 +9655,8 @@ get_scratch_register_on_entry (struct sc 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,17 @@ get_scratch_register_on_entry (struct sc 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) + regno = drap_regno != DX_REG ? DX_REG : AX_REG; + 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 +11189,15 @@ split_stack_prologue_scratch_regno (void 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 +11210,12 @@ split_stack_prologue_scratch_regno (void } 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 +25152,7 @@ ix86_static_chain (const_tree fndecl, bo 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 +25160,12 @@ ix86_static_chain (const_tree fndecl, bo 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 EDX for the static chain. */ + regno = DX_REG; + } else if (ix86_function_regparm (fntype, fndecl) == 3) { /* For regparm 3, we have no free call-clobbered registers in @@ -34799,8 +34823,10 @@ x86_output_mi_thunk (FILE *file, 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; }