From patchwork Tue Dec 19 16:34:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 850920 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-469566-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Q31PjHgy"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3z1Nmk5909z9sNc for ; Wed, 20 Dec 2017 03:35:16 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=qY/zMo7fdJc1qfS7EoUWn6m8iCynzPrGW2lMkiC1q5rEZ0rli4 pFZv2aMenltPpJ5kNUfp48lt/ZB9kzb0RJaXL2FclmAvUejUB8zDpYS52FBRxCl8 ThpQMUSlY8hDbbpMpbuhAiYXTtQ9HWT49uCWuIaKStBHLxfSDan8auREI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=ZHv/78Pv5GUhbUnHvaSN++Gjqhw=; b=Q31PjHgyTyW1GaO7MlMl ZpkSY07AWZMHwREEqYiEED3odFFah7YkJNB0OWn0Z3U3MTVx+BTQ4VQQUrpdTKli chaYKIzgu/lF7BosKaAPg8RME1DpCr85s9B+MToHze6gmSsGM6uNKEhVydf+BjnK lSUtebflz2BKS1BS81Xhfxw= Received: (qmail 108272 invoked by alias); 19 Dec 2017 16:35:10 -0000 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 Received: (qmail 108255 invoked by uid 89); 19 Dec 2017 16:35:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy= X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 19 Dec 2017 16:35:07 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-04.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1eRKrA-00079S-C4 from Tom_deVries@mentor.com for gcc-patches@gcc.gnu.org; Tue, 19 Dec 2017 08:35:04 -0800 Received: from [172.30.72.3] (137.202.0.87) by SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Tue, 19 Dec 2017 16:35:00 +0000 To: GCC Patches From: Tom de Vries Subject: [PATCH, PR83423] Don't call targetm.calls.static_chain in non-static function Message-ID: <4738bbee-9f8d-60e6-68c0-3bbc7bd15bea@mentor.com> Date: Tue, 19 Dec 2017 17:34:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) Hi, this patch fixes PR83423. The default_static_chain hook has implemented a sorry if both STATIC_CHAIN_INCOMING_REGNUM and STATIC_CHAIN_REGNUM are undefined: ... rtx default_static_chain (const_tree ARG_UNUSED (fndecl_or_type), bool incoming_p) { if (incoming_p) { #ifdef STATIC_CHAIN_INCOMING_REGNUM return gen_rtx_REG (Pmode, STATIC_CHAIN_INCOMING_REGNUM); #endif } #ifdef STATIC_CHAIN_REGNUM return gen_rtx_REG (Pmode, STATIC_CHAIN_REGNUM); #endif { static bool issued_error; if (!issued_error) { issued_error = true; sorry ("nested functions not supported on this target"); } /* It really doesn't matter what we return here, so long at it doesn't cause the rest of the compiler to crash. */ return gen_rtx_MEM (Pmode, stack_pointer_rtx); } } ... However, we also call this hook when compiling normal, non-nested functions, so the sorry is effective for both nested and non-nested functions, which is not the intention. The i386 port has a bit that returns NULL for non-nested functions: ... static rtx ix86_static_chain (const_tree fndecl_or_type, bool incoming_p) { unsigned regno; /* While this function won't be called by the middle-end when a static chain isn't needed, it's also used throughout the backend so it's easiest to keep this check centralized. */ if (DECL_P (fndecl_or_type) && !DECL_STATIC_CHAIN (fndecl_or_type)) return NULL; ... and the patch moves this test to a new function rtx_for_static_chain and uses that function instead of targetm.calls.static_chain in the backend, to fix this problem. Bootstrapped and reg-tested on x86_64. OK for trunk? Thanks, - Tom Don't call targetm.calls.static_chain in non-static function 2017-12-19 Tom de Vries PR middle-end/83423 * config/i386/i386.c (ix86_static_chain): Move DECL_STATIC_CHAIN test ... * calls.c (rtx_for_static_chain): ... here. New function. * calls.h (rtx_for_static_chain): Declare. * builtins.c (expand_builtin_setjmp_receiver): Use rtx_for_static_chain instead of targetm.calls.static_chain. * df-scan.c (df_get_entry_block_def_set): Same. --- gcc/builtins.c | 2 +- gcc/calls.c | 11 +++++++++++ gcc/calls.h | 1 + gcc/config/i386/i386.c | 6 ------ gcc/df-scan.c | 3 ++- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/gcc/builtins.c b/gcc/builtins.c index 6b25253..f5f00a3 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -877,7 +877,7 @@ expand_builtin_setjmp_receiver (rtx receiver_label) /* Mark the static chain as clobbered here so life information doesn't get messed up for it. */ - chain = targetm.calls.static_chain (current_function_decl, true); + chain = rtx_for_static_chain (current_function_decl, true); if (chain && REG_P (chain)) emit_clobber (chain); diff --git a/gcc/calls.c b/gcc/calls.c index 8ae9899..25c9750 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -2436,6 +2436,17 @@ rtx_for_function_call (tree fndecl, tree addr) return funexp; } +/* Return the static chain for this function, if any. */ + +rtx +rtx_for_static_chain (const_tree fndecl_or_type, bool incoming_p) +{ + if (DECL_P (fndecl_or_type) && !DECL_STATIC_CHAIN (fndecl_or_type)) + return NULL; + + return targetm.calls.static_chain (fndecl_or_type, incoming_p); +} + /* Internal state for internal_arg_pointer_based_exp and its helpers. */ static struct { diff --git a/gcc/calls.h b/gcc/calls.h index 9b7fa9a..56953bd 100644 --- a/gcc/calls.h +++ b/gcc/calls.h @@ -41,5 +41,6 @@ extern void maybe_warn_alloc_args_overflow (tree, tree, tree[2], int[2]); extern bool get_size_range (tree, tree[2]); extern tree get_attr_nonstring_decl (tree, tree * = NULL); extern void maybe_warn_nonstring_arg (tree, tree); +extern rtx rtx_for_static_chain (const_tree, bool); #endif // GCC_CALLS_H diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 3503743..be5ac42 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -29236,12 +29236,6 @@ ix86_static_chain (const_tree fndecl_or_type, bool incoming_p) { unsigned regno; - /* While this function won't be called by the middle-end when a static - chain isn't needed, it's also used throughout the backend so it's - easiest to keep this check centralized. */ - if (DECL_P (fndecl_or_type) && !DECL_STATIC_CHAIN (fndecl_or_type)) - return NULL; - if (TARGET_64BIT) { /* We always use R10 in 64-bit mode. */ diff --git a/gcc/df-scan.c b/gcc/df-scan.c index 429dab8..d0addd9 100644 --- a/gcc/df-scan.c +++ b/gcc/df-scan.c @@ -34,6 +34,7 @@ along with GCC; see the file COPYING3. If not see #include "regs.h" #include "emit-rtl.h" /* FIXME: Can go away once crtl is moved to rtl.h. */ #include "dumpfile.h" +#include "calls.h" /* The set of hard registers in eliminables[i].from. */ @@ -3518,7 +3519,7 @@ df_get_entry_block_def_set (bitmap entry_block_defs) /* If the function has an incoming STATIC_CHAIN, it has to show up in the entry def set. */ - r = targetm.calls.static_chain (current_function_decl, true); + r = rtx_for_static_chain (current_function_decl, true); if (r && REG_P (r)) bitmap_set_bit (entry_block_defs, REGNO (r));