From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1873) id 76F983858C30; Mon, 13 Mar 2023 21:26:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76F983858C30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678742800; bh=XgD+wlWnvJjGN5WsqIttidj1Wd0WTmPVH89G3I/MSlc=; h=From:To:Subject:Date:From; b=oUwNES4sbNNIeraZnVI4U/iwB0i7vMrmqNSvl3BF6/bomBMy/sL1h2hamn5ecO3NV WBTkcLr4dwYYo7DDuSbIKmQNf5AQihcC3Xf+7zjw8vzmAzGnOFbyjozuSQqcccuCeS AMvS/reFGffneaoppNtV9/nR5Pv/zrwEHMPZaHQg= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Iain Buclaw To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10572] d: Delay removing DECL_EXTERNAL from thunks until funcion has finished X-Act-Checkin: gcc X-Git-Author: Iain Buclaw X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 037a02ac1627a17b046beb3ef5d6299fbba20ab8 X-Git-Newrev: 345a8eb8014f745158a2a51cb43a2482a37a329b Message-Id: <20230313212640.76F983858C30@sourceware.org> Date: Mon, 13 Mar 2023 21:26:40 +0000 (GMT) List-Id: https://gcc.gnu.org/g:345a8eb8014f745158a2a51cb43a2482a37a329b commit r11-10572-g345a8eb8014f745158a2a51cb43a2482a37a329b Author: Iain Buclaw Date: Mon Mar 13 22:04:24 2023 +0100 d: Delay removing DECL_EXTERNAL from thunks until funcion has finished Second part to fixing PR109108, don't blindly generate the associated function definition of all referenced thunks in the compilation. Just delay finishing a thunk until the function gets codegen itself. If the function never gets a definition, then the thunk is left as "extern". gcc/d/ChangeLog: * decl.cc (finish_thunk): Unset DECL_EXTERNAL on thunk. (make_thunk): Set DECL_EXTERNAL on thunk, don't call build_decl_tree. (finish_function): Call finish_thunk on forward referenced thunks. (cherry picked from commit d1bddcaf15a362d88c29337295a0aaaaaa037642) Diff: --- gcc/d/decl.cc | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/gcc/d/decl.cc b/gcc/d/decl.cc index 8f84e5d55f6..c77f10fe615 100644 --- a/gcc/d/decl.cc +++ b/gcc/d/decl.cc @@ -1707,6 +1707,7 @@ finish_thunk (tree thunk, tree function) TREE_ADDRESSABLE (function) = 1; TREE_USED (function) = 1; + DECL_EXTERNAL (thunk) = 0; if (flag_syntax_only) { @@ -1778,21 +1779,14 @@ make_thunk (FuncDeclaration *decl, int offset) if (!DECL_ARGUMENTS (function) || !DECL_RESULT (function)) { - /* Compile the function body before generating the thunk, this is done - even if the decl is external to the current module. */ - if (decl->fbody) - build_decl_tree (decl); - else - { - /* Build parameters for functions that are not being compiled, - so that they can be correctly cloned in finish_thunk. */ - tree function = get_symbol_decl (decl); - DECL_ARGUMENTS (function) = get_fndecl_arguments (decl); - - /* Also build the result decl, which is needed when force creating - the thunk in gimple inside cgraph_node::expand_thunk. */ - DECL_RESULT (function) = get_fndecl_result (decl); - } + /* Build parameters for functions that are not being compiled, + so that they can be correctly cloned in finish_thunk. */ + tree function = get_symbol_decl (decl); + DECL_ARGUMENTS (function) = get_fndecl_arguments (decl); + + /* Also build the result decl, which is needed when force creating + the thunk in gimple inside cgraph_node::expand_thunk. */ + DECL_RESULT (function) = get_fndecl_result (decl); } /* Don't build the thunk if the compilation step failed. */ @@ -1818,11 +1812,10 @@ make_thunk (FuncDeclaration *decl, int offset) DECL_CONTEXT (thunk) = d_decl_context (decl); - /* Thunks inherit the public access of the function they are targeting. - Thunks are connected to the definitions of the functions, so thunks are - not produced for external functions. */ + /* Thunks inherit the public access of the function they are targeting. */ TREE_PUBLIC (thunk) = TREE_PUBLIC (function); - DECL_EXTERNAL (thunk) = DECL_EXTERNAL (function); + /* The thunk has not been defined -- yet. */ + DECL_EXTERNAL (thunk) = 1; /* Thunks are always addressable. */ TREE_ADDRESSABLE (thunk) = 1; @@ -1857,6 +1850,8 @@ make_thunk (FuncDeclaration *decl, int offset) d_keep (thunk); free (CONST_CAST (char *, ident)); + /* Thunks are connected to the definitions of the functions, so thunks are + not produced for external functions. */ if (!DECL_EXTERNAL (function)) finish_thunk (thunk, function); @@ -1982,6 +1977,10 @@ finish_function (tree old_context) DECL_SAVED_TREE (fndecl) = bind; + /* Finish any forward referenced thunks for the function. */ + for (tree t = DECL_LANG_THUNKS (fndecl); t; t = DECL_CHAIN (t)) + finish_thunk (t, fndecl); + if (!errorcount && !global.errors) { /* Dump the D-specific tree IR. */