aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorIain Sandoe <iain@sandoe.co.uk>2020-04-08 08:15:00 +0100
committerIain Sandoe <iain@sandoe.co.uk>2020-04-09 08:25:52 +0100
commit926d39c3816772acde857a8510480d9b287ef760 (patch)
treed155c3ca3048e6ce560bb21d00b498019be285db /gcc
parentfe1837143f1bf1d6b072a3973b00576ee17c30a9 (diff)
downloadgcc-926d39c3816772acde857a8510480d9b287ef760.zip
gcc-926d39c3816772acde857a8510480d9b287ef760.tar.gz
gcc-926d39c3816772acde857a8510480d9b287ef760.tar.bz2
coroutines: Add cleanups, where required, to statements with captured references.
When we promote captured temporaries to local variables, we also remove their initializers from the relevant call expression. This means that we should recompute the need for a cleanup expression once the set of temporaries that remains becomes known. gcc/cp/ChangeLog: 2020-04-08 Iain Sandoe <iain@sandoe.co.uk> Jun Ma <JunMa@linux.alibaba.com> * coroutines.cc (maybe_promote_captured_temps): Add a cleanup expression, if needed, to any call from which we promoted temporaries captured by reference.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/coroutines.cc20
2 files changed, 20 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 50f1857..e63f30b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2020-04-08 Iain Sandoe <iain@sandoe.co.uk>
+ Jun Ma <JunMa@linux.alibaba.com>
+
+ * coroutines.cc (maybe_promote_captured_temps): Add a cleanup
+ expression, if needed, to any call from which we promoted
+ temporaries captured by reference.
+
2020-04-08 Marek Polacek <polacek@redhat.com>
PR c++/94507 - ICE-on-invalid with lambda template.
diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index 983fa65..936be06 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -2798,11 +2798,13 @@ maybe_promote_captured_temps (tree *stmt, void *d)
location_t sloc = EXPR_LOCATION (*stmt);
tree aw_bind
= build3_loc (sloc, BIND_EXPR, void_type_node, NULL, NULL, NULL);
- tree aw_statement_current;
- if (TREE_CODE (*stmt) == CLEANUP_POINT_EXPR)
- aw_statement_current = TREE_OPERAND (*stmt, 0);
- else
- aw_statement_current = *stmt;
+
+ /* Any cleanup point expression might no longer be necessary, since we
+ are removing one or more temporaries. */
+ tree aw_statement_current = *stmt;
+ if (TREE_CODE (aw_statement_current) == CLEANUP_POINT_EXPR)
+ aw_statement_current = TREE_OPERAND (aw_statement_current, 0);
+
/* Collected the scope vars we need move the temps to regular. */
tree aw_bind_body = push_stmt_list ();
tree varlist = NULL_TREE;
@@ -2843,8 +2845,12 @@ maybe_promote_captured_temps (tree *stmt, void *d)
/* Replace all instances of that temp in the original expr. */
cp_walk_tree (&aw_statement_current, replace_proxy, &pr, NULL);
}
- /* What's left should be the original statement with any temporaries
- broken out. */
+
+ /* What's left should be the original statement with any co_await
+ captured temporaries broken out. Other temporaries might remain
+ so see if we need to wrap the revised statement in a cleanup. */
+ aw_statement_current =
+ maybe_cleanup_point_expr_void (aw_statement_current);
add_stmt (aw_statement_current);
BIND_EXPR_BODY (aw_bind) = pop_stmt_list (aw_bind_body);
awpts->captured_temps.empty ();