coroutines: Do not assume parms are named [PR94752].
authorIain Sandoe <iain@sandoe.co.uk>
Sun, 26 Apr 2020 18:34:50 +0000 (19:34 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Sun, 26 Apr 2020 19:29:51 +0000 (20:29 +0100)
Parameters to user-defined coroutines might be unnamed.
In that case, we must synthesize a name for the coroutine
frame copy.

gcc/cp/ChangeLog:

2020-04-26  Iain Sandoe  <iain@sandoe.co.uk>

PR c++/94752
* coroutines.cc (morph_fn_to_coro): Ensure that
unnamed function params have a usable and distinct
frame field name.

gcc/testsuite/ChangeLog:

2020-04-26  Iain Sandoe  <iain@sandoe.co.uk>

PR c++/94752
* g++.dg/coroutines/pr94752.C: New test.

gcc/cp/ChangeLog
gcc/cp/coroutines.cc
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/coroutines/pr94752.C [new file with mode: 0644]

index f0c62783101581029497d7ccc11c28cea938d073..32408f7056bed6c5991b72e9d16c13e8c6a1cb5e 100644 (file)
@@ -1,3 +1,10 @@
+2020-04-26  Iain Sandoe  <iain@sandoe.co.uk>
+
+       PR c++/94752
+       * coroutines.cc (morph_fn_to_coro): Ensure that
+       unnamed function params have a usable and distinct
+       frame field name.
+
 2020-04-24  Jason Merrill  <jason@redhat.com>
 
        PR c++/94583
index 4f254b7fd100b1a4109c6eea698c098c853eabd0..0a5a0c9b1d201a3bbb2fae19a1c42d29f9c0163b 100644 (file)
@@ -3653,6 +3653,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer)
          when we see uses.  */
       param_uses = new hash_map<tree, param_info>;
 
+      unsigned no_name_parm = 0;
       for (tree arg = DECL_ARGUMENTS (orig); arg != NULL;
           arg = DECL_CHAIN (arg))
        {
@@ -3693,8 +3694,14 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer)
            parm.frame_type = actual_type;
          parm.this_ptr = is_this_parameter (arg);
          parm.trivial_dtor = TYPE_HAS_TRIVIAL_DESTRUCTOR (parm.frame_type);
-         tree pname = DECL_NAME (arg);
-         char *buf = xasprintf ("__parm.%s", IDENTIFIER_POINTER (pname));
+         char *buf;
+         if (DECL_NAME (arg))
+           {
+             tree pname = DECL_NAME (arg);
+             buf = xasprintf ("__parm.%s", IDENTIFIER_POINTER (pname));
+           }
+         else
+           buf = xasprintf ("__unnamed_parm.%d", no_name_parm++);
          parm.field_id = coro_make_frame_entry
            (&field_list, buf, actual_type, DECL_SOURCE_LOCATION (arg));
          free (buf);
index c4f5f83552ee3d22b62dcbbe5939c7bf27fd705d..07fe8a6859823edf6b11b289747ae63abcd8d006 100644 (file)
@@ -1,3 +1,8 @@
+2020-04-26  Iain Sandoe  <iain@sandoe.co.uk>
+
+       PR c++/94752
+       * g++.dg/coroutines/pr94752.C: New test.
+
 2020-04-26  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/94737
diff --git a/gcc/testsuite/g++.dg/coroutines/pr94752.C b/gcc/testsuite/g++.dg/coroutines/pr94752.C
new file mode 100644 (file)
index 0000000..89ace6a
--- /dev/null
@@ -0,0 +1,20 @@
+//  { dg-additional-options  "-w" }
+
+#include "coro.h"
+
+using namespace std;
+
+struct task {
+    struct promise_type {
+        promise_type() {}
+        task get_return_object() { return {}; }
+        suspend_never initial_suspend() { return {}; }
+        suspend_never final_suspend() { return {}; }
+        void return_void() {}
+        void unhandled_exception() {}
+    };
+};
+
+task foo(int) {
+    co_return;
+}