coroutines: Bind label_decl of original function to actor function
authorJunMa <JunMa@linux.alibaba.com>
Mon, 20 Jan 2020 09:46:32 +0000 (17:46 +0800)
committerJunMa <JunMa@linux.alibaba.com>
Mon, 3 Feb 2020 01:24:27 +0000 (09:24 +0800)
gcc/cp
    * coroutines.cc (transform_await_wrapper): Set actor funcion as
    new context of label_decl.
    (build_actor_fn): Fill new field of await_xform_data.

gcc/testsuite
    * g++.dg/coroutines/co-await-04-control-flow.C: Add label.

gcc/cp/ChangeLog
gcc/cp/coroutines.cc
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/coroutines/torture/co-await-04-control-flow.C

index ed1c64f18fb728f693cc3e066f11240c04dae8d4..4e2b0c5e4e38188df04e450387462db3dd8f8acf 100644 (file)
@@ -1,3 +1,9 @@
+2020-02-03  Jun Ma <JunMa@linux.alibaba.com>
+
+       * coroutines.cc (transform_await_wrapper): Set actor funcion as
+       new context of label_decl.
+       (build_actor_fn): Fill new field of await_xform_data.
+
 2020-02-02  Marek Polacek  <polacek@redhat.com>
 
        PR c++/93530 - ICE on invalid alignas in a template.
index f7f85cb7643b5b604716e1da800830229a5ff25b..62d92d9fc98099cdc8cb55e8ceff6e0c1d090773 100644 (file)
@@ -1580,6 +1580,7 @@ static hash_map<tree, suspend_point_info> *suspend_points;
 
 struct await_xform_data
 {
+  tree actor_fn;   /* Decl for context.  */
   tree actor_frame;
   tree promise_proxy;
   tree real_promise;
@@ -1660,12 +1661,16 @@ transform_await_expr (tree await_expr, await_xform_data *xform)
 static tree
 transform_await_wrapper (tree *stmt, int *do_subtree, void *d)
 {
+  /* Set actor function as new DECL_CONTEXT of label_decl.  */
+  struct await_xform_data *xform = (struct await_xform_data *) d;
+  if (TREE_CODE (*stmt) == LABEL_DECL
+      && DECL_CONTEXT (*stmt) != xform->actor_fn)
+    DECL_CONTEXT (*stmt) = xform->actor_fn;
+
   if (TREE_CODE (*stmt) != CO_AWAIT_EXPR && TREE_CODE (*stmt) != CO_YIELD_EXPR)
     return NULL_TREE;
 
   tree await_expr = *stmt;
-  await_xform_data *xform = (await_xform_data *) d;
-
   *stmt = transform_await_expr (await_expr, xform);
   if (*stmt == error_mark_node)
     *do_subtree = 0;
@@ -2018,7 +2023,7 @@ build_actor_fn (location_t loc, tree coro_frame_type, tree actor, tree fnbody,
      decide where to put things.  */
 
   await_xform_data xform
-    = {actor_frame, promise_proxy, ap, self_h_proxy, ash};
+    = {actor, actor_frame, promise_proxy, ap, self_h_proxy, ash};
 
   /* Get a reference to the initial suspend var in the frame.  */
   transform_await_expr (initial_await, &xform);
index 74cbead32fb0ab88686a9d447fa9f031fa052f97..5471778da0babbf2178f159610420bc501b08026 100644 (file)
@@ -1,3 +1,7 @@
+2020-02-03  Jun Ma <JunMa@linux.alibaba.com>
+
+       * g++.dg/coroutines/co-await-04-control-flow.C: Add label.
+
 2020-02-02  Marek Polacek  <polacek@redhat.com>
 
        PR c++/93530 - ICE on invalid alignas in a template.
index 9bc99e875d095542cdfb0d89fcd7f3c9b0e28283..e8da2d2e2ad7b815c07aaf2fce81ac60739b81f7 100644 (file)
@@ -16,9 +16,11 @@ coro1
 f ()
 {
   if (gX < 12) {
+L1:
     gX += y;
     gX += co_await 11;
   } else
+L2:
     gX += co_await 12;
     
   co_return gX;