https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83423
Bug ID: 83423 Summary: default_static_chain is sorry for non-nested functions Product: gcc Version: 8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: vries at gcc dot gnu.org Target Milestone: --- 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. 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; ... Using the same code in default_static_chain fixes the problem. There are two ways to fix this: - conservative: we add the test before the sorry, such that it's only effective for targets that do not define STATIC_CHAIN_INCOMING_REGNUM and STATIC_CHAIN_REGNUM (typically, this situation happens during bringup of a target. I'm not certain this triggers for any current trunk target) - optimal: we add the test at the start of the function, such that it's effective for all targets that use it (all but i386, moxie, xtensa)