[12/25] Make default_static_chain return NULL in non-static functions

Message ID db4350f43a24136d524b352e1ecef9b9acf6b606.1536144068.git.ams@codesourcery.com
State New
Headers show
Series
  • AMD GCN Port
Related show

Commit Message

Andrew Stubbs Sept. 5, 2018, 11:50 a.m.
This patch allows default_static_chain to be called from the back-end without
it knowing if the function is static or not.  Or, to put it another way,
without duplicating the check everywhere it's used.

2018-09-05  Tom de Vries  <tom@codesourcery.com>

	gcc/
	* targhooks.c (default_static_chain): Return NULL in non-static
	functions.
---
 gcc/targhooks.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Richard Sandiford Sept. 17, 2018, 6:55 p.m. | #1
<ams@codesourcery.com> writes:
> This patch allows default_static_chain to be called from the back-end without

> it knowing if the function is static or not.  Or, to put it another way,

> without duplicating the check everywhere it's used.

>

> 2018-09-05  Tom de Vries  <tom@codesourcery.com>

>

> 	gcc/

> 	* targhooks.c (default_static_chain): Return NULL in non-static

> 	functions.

> ---

>  gcc/targhooks.c | 8 +++++++-

>  1 file changed, 7 insertions(+), 1 deletion(-)

>

> diff --git a/gcc/targhooks.c b/gcc/targhooks.c

> index afd56f3..742cfbf 100644

> --- a/gcc/targhooks.c

> +++ b/gcc/targhooks.c

> @@ -1021,8 +1021,14 @@ default_internal_arg_pointer (void)

>  }

>  

>  rtx

> -default_static_chain (const_tree ARG_UNUSED (fndecl_or_type), bool incoming_p)

> +default_static_chain (const_tree fndecl_or_type, bool incoming_p)

>  {

> +  /* 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 (incoming_p)

>      {

>  #ifdef STATIC_CHAIN_INCOMING_REGNUM


Not sure about this.  The caller has to make sure the query's sensible
for types, since types don't indicate whether they need a static chain.
Allowing it to be more sloppy for decls seems a bit dangerous.

Which part of the backend needs this?  I couldn't tell from a quick
grep where the call came from.

Thanks,
Richard
Andrew Stubbs Sept. 28, 2018, 2:22 p.m. | #2
On 17/09/18 19:55, Richard Sandiford wrote:
> Which part of the backend needs this?  I couldn't tell from a quick

> grep where the call came from.


It wasn't called directly, but from builtins.c and df-scan.c.

I needed this for GCC7, but apparently in newer source-bases the problem 
has been fixed another way.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83423

I'll drop this patch.

Andrew

Patch

diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index afd56f3..742cfbf 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -1021,8 +1021,14 @@  default_internal_arg_pointer (void)
 }
 
 rtx
-default_static_chain (const_tree ARG_UNUSED (fndecl_or_type), bool incoming_p)
+default_static_chain (const_tree fndecl_or_type, bool incoming_p)
 {
+  /* 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 (incoming_p)
     {
 #ifdef STATIC_CHAIN_INCOMING_REGNUM