This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH to vector delete
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 21 May 2003 19:22:43 -0400
- Subject: C++ PATCH to vector delete
g++.old-deja/g++.oliva/delete2.C deletes the result of a vector
new-expression. As a result, we end up expanding a TARGET_EXPR with a
cleanup inside of a STMT_EXPR, but the cleanup is supposed to live past the
end of the STMT_EXPR. This violates reasonable nesting practice, and
breaks this testcase and delete3.C on the tree-ssa branch.
This patch just copies the pointer expression to be deleted into a
temporary and passes that to the vec-delete code; this way the cleanup is
expanded before the STMT_EXPR, and everyone is happy.
I also removed a couple of redundant calls to stabilize_reference while I
was there.
Tested i686-pc-linux-gnu, applied to trunk and tree-ssa.
2003-05-21 Jason Merrill <jason@redhat.com>
* init.c (build_vec_delete): Copy the address into a temporary
variable before calling build_vec_delete_1.
* decl2.c (delete_sanity): Don't call stabilize_reference.
*** decl2.c.~1~ 2003-05-07 11:15:47.000000000 -0400
--- decl2.c 2003-05-21 18:41:00.000000000 -0400
*************** delete_sanity (tree exp, tree size, int
*** 492,499 ****
if (TREE_CODE (exp) == OFFSET_REF)
exp = resolve_offset_ref (exp);
exp = convert_from_reference (exp);
! t = stabilize_reference (exp);
! t = build_expr_type_conversion (WANT_POINTER, t, true);
if (t == NULL_TREE || t == error_mark_node)
{
--- 492,498 ----
if (TREE_CODE (exp) == OFFSET_REF)
exp = resolve_offset_ref (exp);
exp = convert_from_reference (exp);
! t = build_expr_type_conversion (WANT_POINTER, exp, true);
if (t == NULL_TREE || t == error_mark_node)
{
*** init.c.~1~ 2003-05-14 15:32:25.000000000 -0400
--- init.c 2003-05-21 18:39:01.000000000 -0400
*************** build_vec_delete (base, maxindex, auto_d
*** 3359,3379 ****
int use_global_delete;
{
tree type;
if (TREE_CODE (base) == OFFSET_REF)
base = resolve_offset_ref (base);
type = TREE_TYPE (base);
- base = stabilize_reference (base);
-
if (TREE_CODE (type) == POINTER_TYPE)
{
/* Step back one from start of vector, and read dimension. */
tree cookie_addr;
if (TREE_SIDE_EFFECTS (base))
! base = save_expr (base);
type = strip_array_types (TREE_TYPE (type));
cookie_addr = build (MINUS_EXPR,
build_pointer_type (sizetype),
--- 3359,3382 ----
int use_global_delete;
{
tree type;
+ tree rval;
+ tree base_init = NULL_TREE;
if (TREE_CODE (base) == OFFSET_REF)
base = resolve_offset_ref (base);
type = TREE_TYPE (base);
if (TREE_CODE (type) == POINTER_TYPE)
{
/* Step back one from start of vector, and read dimension. */
tree cookie_addr;
if (TREE_SIDE_EFFECTS (base))
! {
! base_init = get_target_expr (base);
! base = TARGET_EXPR_SLOT (base_init);
! }
type = strip_array_types (TREE_TYPE (type));
cookie_addr = build (MINUS_EXPR,
build_pointer_type (sizetype),
*************** build_vec_delete (base, maxindex, auto_d
*** 3388,3394 ****
type = strip_array_types (type);
base = build_unary_op (ADDR_EXPR, base, 1);
if (TREE_SIDE_EFFECTS (base))
! base = save_expr (base);
}
else
{
--- 3391,3400 ----
type = strip_array_types (type);
base = build_unary_op (ADDR_EXPR, base, 1);
if (TREE_SIDE_EFFECTS (base))
! {
! base_init = get_target_expr (base);
! base = TARGET_EXPR_SLOT (base_init);
! }
}
else
{
*************** build_vec_delete (base, maxindex, auto_d
*** 3397,3402 ****
return error_mark_node;
}
! return build_vec_delete_1 (base, maxindex, type, auto_delete_vec,
use_global_delete);
}
--- 3403,3412 ----
return error_mark_node;
}
! rval = build_vec_delete_1 (base, maxindex, type, auto_delete_vec,
use_global_delete);
+ if (base_init)
+ rval = build (COMPOUND_EXPR, TREE_TYPE (rval), base_init, rval);
+
+ return rval;
}