From 4b522b8f339f4e7844843d30f38ea9459d908e3c Mon Sep 17 00:00:00 2001 From: Tom de Vries Date: Wed, 20 Dec 2017 00:46:38 +0000 Subject: [PATCH] Don't call targetm.calls.static_chain in non-static function 2017-12-20 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. From-SVN: r255849 --- gcc/ChangeLog | 10 ++++++++++ gcc/builtins.c | 2 +- gcc/calls.c | 11 +++++++++++ gcc/calls.h | 1 + gcc/config/i386/i386.c | 6 ------ gcc/df-scan.c | 3 ++- 6 files changed, 25 insertions(+), 8 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7e803a31542..9284a8c07fc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2017-12-20 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. + 2017-12-19 Tom de Vries PR tree-optimization/83493 diff --git a/gcc/builtins.c b/gcc/builtins.c index 6bff904d8be..3e8ea95d729 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -878,7 +878,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 da6c96b8131..6057aa65da0 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -2460,6 +2460,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 641166e23a3..1aab140ae7b 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 tree get_attr_nonstring_decl (tree, tree * = NULL); extern void maybe_warn_nonstring_arg (tree, tree); extern bool get_size_range (tree, tree[2], bool = false); +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 85988cf2de0..48d5640f84e 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 429dab8a99b..d0addd9e150 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)); -- 2.30.2