public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] coroutines: Adjust outlined function names [PR95520].
@ 2021-07-09 18:18 Iain Sandoe
  2021-07-09 21:40 ` Jason Merrill
  0 siblings, 1 reply; 6+ messages in thread
From: Iain Sandoe @ 2021-07-09 18:18 UTC (permalink / raw)
  To: GCC Patches

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 <iain@sandoe.co.uk>

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 = get_fn_local_identifier (orig, name);
+  tree fn_name;
   location_t loc = DECL_SOURCE_LOCATION (orig);
-  tree fn = build_lang_decl (FUNCTION_DECL, fn_name, fn_type);
+  tree fn = build_lang_decl (FUNCTION_DECL, DECL_NAME (orig), fn_type);
+  if (tree da_name = DECL_ASSEMBLER_NAME (orig))
+    {
+      char *buf = xasprintf ("%s.%s", IDENTIFIER_POINTER (da_name), name);
+      fn_name = get_identifier (buf);
+      free (buf);
+    }
+  else
+    fn_name = get_fn_local_identifier (orig, name);
+
+  SET_DECL_ASSEMBLER_NAME (fn, fn_name);
   DECL_CONTEXT (fn) = DECL_CONTEXT (orig);
   DECL_SOURCE_LOCATION (fn) = loc;
   DECL_ARTIFICIAL (fn) = 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 <coroutine>
+#include <cstdio>
+
+struct pt
+{
+    using handle_t = std::coroutine_handle<pt>;
+    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<pt::handle_t>
+    { using promise_type = pt; };
+
+static pt::handle_t MyFoo ()
+{ 
+    printf ("coroutine name: %s\n", __builtin_FUNCTION());
+    co_return;
+}
+
+int main()
+{
+    MyFoo ();
+}
-- 
2.24.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-07-13 19:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-09 18:18 [PATCH] coroutines: Adjust outlined function names [PR95520] Iain Sandoe
2021-07-09 21:40 ` Jason Merrill
2021-07-11 13:03   ` [PATCH V2] " Iain Sandoe
2021-07-12 19:40     ` Jason Merrill
2021-07-13  8:11       ` Iain Sandoe
2021-07-13 19:52         ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).