Commit 8b5e2ce4 by Jason Merrill Committed by Jason Merrill

init.c (build_new_1): Don't reuse a TARGET_EXPR in an expression.

        * init.c (build_new_1): Don't reuse a TARGET_EXPR in an
        expression.  Undo some of the recent reorg.

From-SVN: r66594
parent 044075ac
2003-05-08 Jason Merrill <jason@redhat.com>
* init.c (build_new_1): Don't reuse a TARGET_EXPR in an
expression. Undo some of the recent reorg.
2003-05-07 Richard Henderson <rth@redhat.com> 2003-05-07 Richard Henderson <rth@redhat.com>
PR c++/10570 PR c++/10570
......
...@@ -2172,6 +2172,7 @@ build_new_1 (exp) ...@@ -2172,6 +2172,7 @@ build_new_1 (exp)
a VAR_DECL and is therefore reusable. */ a VAR_DECL and is therefore reusable. */
tree alloc_node; tree alloc_node;
tree alloc_fn; tree alloc_fn;
tree cookie_expr, init_expr;
int has_array = 0; int has_array = 0;
enum tree_code code; enum tree_code code;
int nothrow, check_new; int nothrow, check_new;
...@@ -2357,13 +2358,11 @@ build_new_1 (exp) ...@@ -2357,13 +2358,11 @@ build_new_1 (exp)
can use it more than once. */ can use it more than once. */
full_pointer_type = build_pointer_type (full_type); full_pointer_type = build_pointer_type (full_type);
alloc_expr = get_target_expr (build_nop (full_pointer_type, alloc_call)); alloc_expr = get_target_expr (build_nop (full_pointer_type, alloc_call));
alloc_node = TREE_OPERAND (alloc_expr, 0); alloc_node = TARGET_EXPR_SLOT (alloc_expr);
rval = NULL_TREE;
if (cookie_size) if (cookie_size)
{ {
tree cookie; tree cookie;
tree cookie_expr;
/* Adjust so we're pointing to the start of the object. */ /* Adjust so we're pointing to the start of the object. */
data_addr = get_target_expr (build (PLUS_EXPR, full_pointer_type, data_addr = get_target_expr (build (PLUS_EXPR, full_pointer_type,
...@@ -2377,18 +2376,17 @@ build_new_1 (exp) ...@@ -2377,18 +2376,17 @@ build_new_1 (exp)
cookie = build_indirect_ref (cookie, NULL); cookie = build_indirect_ref (cookie, NULL);
cookie_expr = build (MODIFY_EXPR, sizetype, cookie, nelts); cookie_expr = build (MODIFY_EXPR, sizetype, cookie, nelts);
TREE_SIDE_EFFECTS (cookie_expr) = 1; data_addr = TARGET_EXPR_SLOT (data_addr);
rval = build (COMPOUND_EXPR, void_type_node, data_addr, cookie_expr);
data_addr = TREE_OPERAND (data_addr, 0);
} }
else else
data_addr = alloc_node; {
cookie_expr = NULL_TREE;
data_addr = alloc_node;
}
/* Now initialize the allocated object. */ /* Now initialize the allocated object. */
if (is_initialized) if (is_initialized)
{ {
tree init_expr;
init_expr = build_indirect_ref (data_addr, NULL); init_expr = build_indirect_ref (data_addr, NULL);
if (init == void_zero_node) if (init == void_zero_node)
...@@ -2502,24 +2500,36 @@ build_new_1 (exp) ...@@ -2502,24 +2500,36 @@ build_new_1 (exp)
end)); end));
} }
} }
if (rval)
rval = build (COMPOUND_EXPR, TREE_TYPE (init_expr), rval, init_expr);
else
rval = init_expr;
} }
else
init_expr = NULL_TREE;
/* Now build up the return value in reverse order. */
rval = build (COMPOUND_EXPR, TREE_TYPE (alloc_node), rval, data_addr); rval = data_addr;
if (check_new) if (init_expr)
rval = build (COMPOUND_EXPR, TREE_TYPE (rval), init_expr, rval);
if (cookie_expr)
rval = build (COMPOUND_EXPR, TREE_TYPE (rval), cookie_expr, rval);
if (rval == alloc_node)
/* If we don't have an initializer or a cookie, strip the TARGET_EXPR
and return the call (which doesn't need to be adjusted). */
rval = TARGET_EXPR_INITIAL (alloc_expr);
else
{ {
tree ifexp = cp_build_binary_op (NE_EXPR, alloc_node, integer_zero_node); if (check_new)
rval = build_conditional_expr (ifexp, rval, alloc_node); {
} tree ifexp = cp_build_binary_op (NE_EXPR, alloc_node,
integer_zero_node);
rval = build_conditional_expr (ifexp, rval, alloc_node);
}
/* Perform the allocation before anything else, so that ALLOC_NODE /* Perform the allocation before anything else, so that ALLOC_NODE
has been initialized before we start using it. */ has been initialized before we start using it. */
rval = build (COMPOUND_EXPR, TREE_TYPE (rval), alloc_expr, rval); rval = build (COMPOUND_EXPR, TREE_TYPE (rval), alloc_expr, rval);
}
/* Convert to the final type. */ /* Convert to the final type. */
return build_nop (pointer_type, rval); return build_nop (pointer_type, rval);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment