[PATCH, PR83423] Don't call targetm.calls.static_chain in non-static function
Jeff Law
law@redhat.com
Wed Dec 20 00:12:00 GMT 2017
On 12/19/2017 09:34 AM, Tom de Vries wrote:
> 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
>
> 0001-Don-t-call-targetm.calls.static_chain-in-non-static-function.patch
>
>
> Don't call targetm.calls.static_chain in non-static function
>
> 2017-12-19 Tom de Vries <tom@codesourcery.com>
>
> 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.
OK.
jeff
More information about the Gcc-patches
mailing list