coroutines: Ensure distinct DTOR trees [PR95137].

Message ID 8291EEA1-37E7-4E82-B2D7-50646D0BC524@sandoe.co.uk
State New
Headers show
Series
  • coroutines: Ensure distinct DTOR trees [PR95137].
Related show

Commit Message

Iain Sandoe May 22, 2020, 11:19 a.m.
Hi

This is almost obvious - except perhaps I’m missing some more
efficient way of doing it; it seems less than ideal to have to build the
ctor call twice with exactly the same inputs.

If there’s no better way ….

tested on x86_64-darwin, linux
OK for master, 10.2?
thanks
iain
        /* Initialize the var from the provided 'o' expression.  */
@@ -1595,7 +1589,12 @@ expand_one_await_expression (tree *stmt, tree  
*await_expr, void *d)
    destroy_label = build_stmt (loc, LABEL_EXPR, destroy_label);
    append_to_statement_list (destroy_label, &body_list);
    if (needs_dtor)
-    append_to_statement_list (dtor, &body_list);
+    {
+      tree dtor = build_special_member_call (var, complete_dtor_identifier,
+					     NULL, await_type, LOOKUP_NORMAL,
+					     tf_warning_or_error);
+      append_to_statement_list (dtor, &body_list);
+    }
    r = build1_loc (loc, GOTO_EXPR, void_type_node, data->cleanup);
    append_to_statement_list (r, &body_list);
 
@@ -1630,7 +1629,12 @@ expand_one_await_expression (tree *stmt, tree  
*await_expr, void *d)
    /* Get a pointer to the revised statment.  */
    tree *revised = tsi_stmt_ptr (tsi_last (stmt_list));
    if (needs_dtor)
-    append_to_statement_list (dtor, &stmt_list);
+    {
+      tree dtor = build_special_member_call (var, complete_dtor_identifier,
+					     NULL, await_type, LOOKUP_NORMAL,
+					     tf_warning_or_error);
+      append_to_statement_list (dtor, &stmt_list);
+    }
    data->index += 2;
 
    /* Replace the original statement with the expansion.  */
-- 
2.24.1

Comments

Nathan Sidwell June 8, 2020, 7:29 p.m. | #1
On 5/22/20 7:19 AM, Iain Sandoe wrote:
> Hi

> 

> This is almost obvious - except perhaps I’m missing some more

> efficient way of doing it; it seems less than ideal to have to build the

> ctor call twice with exactly the same inputs.

> 

> If there’s no better way ….


ok.

nathan

-- 
Nathan Sidwell

Patch

====
Part of the PR notes that there are UBSAN fails for the coroutines
test suite.  These are primarily related to the use of the same DTOR
tree in the two edges from the await block.  Fixed by building a new
tree for each.

gcc/cp/ChangeLog:

2020-05-19  Iain Sandoe  <iain@sandoe.co.uk>

	PR sanitizer/95137
	* coroutines.cc (expand_one_await_expression): Build separate
	DTOR trees for the awaitable object on the destroy and resume
	paths.
---
  gcc/cp/coroutines.cc | 22 +++++++++++++---------
  1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc
index b79e2c66b70..18f74d034b7 100644
--- a/gcc/cp/coroutines.cc
+++ b/gcc/cp/coroutines.cc
@@ -1468,19 +1468,13 @@  expand_one_await_expression (tree *stmt, tree  
*await_expr, void *d)
    tree resume_label = create_named_label_with_ctx (loc, buf, actor);
    tree empty_list = build_empty_stmt (loc);
 
-  tree dtor = NULL_TREE;
    tree await_type = TREE_TYPE (var);
-  if (needs_dtor)
-    dtor = build_special_member_call (var, complete_dtor_identifier, NULL,
-				      await_type, LOOKUP_NORMAL,
-				      tf_warning_or_error);
-
    tree stmt_list = NULL;
    tree t_expr = STRIP_NOPS (expr);
    tree r;
    tree *await_init = NULL;
    if (t_expr == var)
-    dtor = NULL_TREE;
+    needs_dtor = false;
    else
      {