From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp002.apm-internet.net (smtp002.apm-internet.net [85.119.248.221]) by sourceware.org (Postfix) with ESMTPS id A920F385802A for ; Fri, 9 Jul 2021 18:18:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A920F385802A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sandoe.co.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=sandoe.co.uk Received: (qmail 24142 invoked from network); 9 Jul 2021 18:18:18 -0000 X-APM-Out-ID: 16258546982413 X-APM-Authkey: 257869/1(257869/1) 13 Received: from unknown (HELO ?192.168.1.214?) (81.138.1.83) by smtp002.apm-internet.net with SMTP; 9 Jul 2021 18:18:18 -0000 From: Iain Sandoe Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.21\)) Subject: [PATCH] coroutines: Adjust outlined function names [PR95520]. Message-Id: Date: Fri, 9 Jul 2021 19:18:18 +0100 To: GCC Patches X-Mailer: Apple Mail (2.3445.104.21) X-Spam-Status: No, score=-16.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_COUK, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Jul 2021 18:18:21 -0000 Hi, The mechanism used to date for uniquing the coroutine helper functions (actor, destroy) was over-complicating things and leading to the noted PR and also difficulties in setting breakpoints on these functions (so this will help PR99215 as well). The revised mangling matches the form used by clang. OK for master & backports? thanks Iain Signed-off-by: Iain Sandoe PR c++/95520 - [coroutines] __builtin_FUNCTION() returns mangled .actor = instead of original function name PR c++/95520 gcc/cp/ChangeLog: * coroutines.cc (act_des_fn): Adjust coroutine helper function name mangling. gcc/testsuite/ChangeLog: * g++.dg/coroutines/pr95520.C: New test. --- gcc/cp/coroutines.cc | 14 +++++++++-- gcc/testsuite/g++.dg/coroutines/pr95520.C | 29 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/coroutines/pr95520.C diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index 54ffdc8d062..1a3ab58e044 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -3985,9 +3985,19 @@ register_local_var_uses (tree *stmt, int = *do_subtree, void *d) static tree act_des_fn (tree orig, tree fn_type, tree coro_frame_ptr, const char* = name) { - tree fn_name =3D get_fn_local_identifier (orig, name); + tree fn_name; location_t loc =3D DECL_SOURCE_LOCATION (orig); - tree fn =3D build_lang_decl (FUNCTION_DECL, fn_name, fn_type); + tree fn =3D build_lang_decl (FUNCTION_DECL, DECL_NAME (orig), = fn_type); + if (tree da_name =3D DECL_ASSEMBLER_NAME (orig)) + { + char *buf =3D xasprintf ("%s.%s", IDENTIFIER_POINTER (da_name), = name); + fn_name =3D get_identifier (buf); + free (buf); + } + else + fn_name =3D get_fn_local_identifier (orig, name); + + SET_DECL_ASSEMBLER_NAME (fn, fn_name); DECL_CONTEXT (fn) =3D DECL_CONTEXT (orig); DECL_SOURCE_LOCATION (fn) =3D loc; DECL_ARTIFICIAL (fn) =3D true; diff --git a/gcc/testsuite/g++.dg/coroutines/pr95520.C = b/gcc/testsuite/g++.dg/coroutines/pr95520.C new file mode 100644 index 00000000000..4849b0789c7 --- /dev/null +++ b/gcc/testsuite/g++.dg/coroutines/pr95520.C @@ -0,0 +1,29 @@ +// { dg-do run } +// { dg-output "coroutine name: MyFoo" } +#include +#include + +struct pt +{ + using handle_t =3D std::coroutine_handle; + auto get_return_object() noexcept { return = handle_t::from_promise(*this); } + + std::suspend_never initial_suspend () const noexcept { return {}; } + std::suspend_never final_suspend () const noexcept { return {}; } + void return_void() const noexcept {} + void unhandled_exception() const noexcept {} +}; + +template <> struct std::coroutine_traits + { using promise_type =3D pt; }; + +static pt::handle_t MyFoo () +{=20 + printf ("coroutine name: %s\n", __builtin_FUNCTION()); + co_return; +} + +int main() +{ + MyFoo (); +} --=20 2.24.1