This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for c++/8564
- From: Jason Merrill <jason at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 16 Jan 2003 22:43:17 -0500
- Subject: C++ PATCH for c++/8564
An earlier patch of mine to simplify build_vec_init was causing problems
because I changed build_new_1 to create a VLA type for it to initialize.
This broke because VLAs don't work properly at file scope. I tried briefly
to get them to work properly, and then gave up and changed build_new_1 back
to passing the non-constant bound separately.
Test in g++.dg/init/new3.C. Tested i686-pc-linux-gnu. Applied to trunk
and 3.3.
2003-01-16 Jason Merrill <jason@redhat.com>
PR c++/8564
* init.c (build_vec_init): Re-add maxindex parm.
(perform_member_init, build_aggr_init): Pass it.
(build_new_1): Pass it. Use an incomplete array type for full_type.
* typeck.c (build_modify_expr): Pass it.
* cp-tree.h: Adjust.
*** cp-tree.h.~1~ 2003-01-14 02:39:13.000000000 -0500
--- cp-tree.h 2003-01-16 17:45:29.000000000 -0500
*************** extern tree build_member_call (tree, t
*** 3955,3961 ****
extern tree build_offset_ref (tree, tree);
extern tree resolve_offset_ref (tree);
extern tree build_new (tree, tree, tree, int);
! extern tree build_vec_init (tree, tree, int);
extern tree build_x_delete (tree, int, tree);
extern tree build_delete (tree, tree, special_function_kind, int, int);
extern void push_base_cleanups (void);
--- 3955,3961 ----
extern tree build_offset_ref (tree, tree);
extern tree resolve_offset_ref (tree);
extern tree build_new (tree, tree, tree, int);
! extern tree build_vec_init (tree, tree, tree, int);
extern tree build_x_delete (tree, int, tree);
extern tree build_delete (tree, tree, special_function_kind, int, int);
extern void push_base_cleanups (void);
*** init.c.~1~ 2003-01-14 02:39:13.000000000 -0500
--- init.c 2003-01-16 17:49:49.000000000 -0500
*************** perform_member_init (tree member, tree i
*** 353,359 ****
&& TREE_CODE (TREE_TYPE (TREE_VALUE (init))) == ARRAY_TYPE)
{
/* Initialization of one array from another. */
! finish_expr_stmt (build_vec_init (decl, TREE_VALUE (init), 1));
}
else
finish_expr_stmt (build_aggr_init (decl, init, 0));
--- 353,360 ----
&& TREE_CODE (TREE_TYPE (TREE_VALUE (init))) == ARRAY_TYPE)
{
/* Initialization of one array from another. */
! finish_expr_stmt (build_vec_init (decl, NULL_TREE, TREE_VALUE (init),
! /* from_array=*/1));
}
else
finish_expr_stmt (build_aggr_init (decl, init, 0));
*************** build_aggr_init (exp, init, flags)
*** 1115,1121 ****
TREE_TYPE (exp) = TYPE_MAIN_VARIANT (type);
if (itype && cp_type_quals (itype) != TYPE_UNQUALIFIED)
TREE_TYPE (init) = TYPE_MAIN_VARIANT (itype);
! stmt_expr = build_vec_init (exp, init,
init && same_type_p (TREE_TYPE (init),
TREE_TYPE (exp)));
TREE_READONLY (exp) = was_const;
--- 1116,1122 ----
TREE_TYPE (exp) = TYPE_MAIN_VARIANT (type);
if (itype && cp_type_quals (itype) != TYPE_UNQUALIFIED)
TREE_TYPE (init) = TYPE_MAIN_VARIANT (itype);
! stmt_expr = build_vec_init (exp, NULL_TREE, init,
init && same_type_p (TREE_TYPE (init),
TREE_TYPE (exp)));
TREE_READONLY (exp) = was_const;
*************** build_new_1 (exp)
*** 2155,2160 ****
--- 2156,2162 ----
tree placement, init;
tree type, true_type, size, rval, t;
tree full_type;
+ tree outer_nelts = NULL_TREE;
tree nelts = NULL_TREE;
tree alloc_call, alloc_expr, alloc_node;
tree alloc_fn;
*************** build_new_1 (exp)
*** 2184,2195 ****
if (TREE_CODE (type) == ARRAY_REF)
{
has_array = 1;
! nelts = TREE_OPERAND (type, 1);
type = TREE_OPERAND (type, 0);
! full_type = cp_build_binary_op (MINUS_EXPR, nelts, integer_one_node);
! full_type = build_index_type (full_type);
! full_type = build_cplus_array_type (type, full_type);
}
else
full_type = type;
--- 2186,2196 ----
if (TREE_CODE (type) == ARRAY_REF)
{
has_array = 1;
! nelts = outer_nelts = TREE_OPERAND (type, 1);
type = TREE_OPERAND (type, 0);
! /* Use an incomplete array type to avoid VLA headaches. */
! full_type = build_cplus_array_type (type, NULL_TREE);
}
else
full_type = type;
*************** build_new_1 (exp)
*** 2379,2385 ****
pedwarn ("ISO C++ forbids initialization in array new");
if (has_array)
! init_expr = build_vec_init (init_expr, init, 0);
else if (TYPE_NEEDS_CONSTRUCTING (type))
init_expr = build_special_member_call (init_expr,
complete_ctor_identifier,
--- 2380,2390 ----
pedwarn ("ISO C++ forbids initialization in array new");
if (has_array)
! init_expr
! = build_vec_init (init_expr,
! cp_build_binary_op (MINUS_EXPR, outer_nelts,
! integer_one_node),
! init, /*from_array=*/0);
else if (TYPE_NEEDS_CONSTRUCTING (type))
init_expr = build_special_member_call (init_expr,
complete_ctor_identifier,
*************** get_temp_regvar (type, init)
*** 2710,2715 ****
--- 2715,2723 ----
initialization of a vector of aggregate types.
BASE is a reference to the vector, of ARRAY_TYPE.
+ MAXINDEX is the maximum index of the array (one less than the
+ number of elements). It is only used if
+ TYPE_DOMAIN (TREE_TYPE (BASE)) == NULL_TREE.
INIT is the (possibly NULL) initializer.
FROM_ARRAY is 0 if we should init everything with INIT
*************** get_temp_regvar (type, init)
*** 2720,2727 ****
but use assignment instead of initialization. */
tree
! build_vec_init (base, init, from_array)
! tree base, init;
int from_array;
{
tree rval;
--- 2728,2735 ----
but use assignment instead of initialization. */
tree
! build_vec_init (base, maxindex, init, from_array)
! tree base, init, maxindex;
int from_array;
{
tree rval;
*************** build_vec_init (base, init, from_array)
*** 2741,2749 ****
tree try_block = NULL_TREE;
tree try_body = NULL_TREE;
int num_initialized_elts = 0;
- tree maxindex = array_type_nelts (TREE_TYPE (base));
! if (maxindex == error_mark_node)
return error_mark_node;
if (init
--- 2749,2759 ----
tree try_block = NULL_TREE;
tree try_body = NULL_TREE;
int num_initialized_elts = 0;
! if (TYPE_DOMAIN (atype))
! maxindex = array_type_nelts (atype);
!
! if (maxindex == NULL_TREE || maxindex == error_mark_node)
return error_mark_node;
if (init
*************** build_vec_init (base, init, from_array)
*** 2934,2940 ****
sorry
("cannot initialize multi-dimensional array with initializer");
elt_init = build_vec_init (build1 (INDIRECT_REF, type, base),
! 0, 0);
}
else
elt_init = build_aggr_init (build1 (INDIRECT_REF, type, base),
--- 2944,2950 ----
sorry
("cannot initialize multi-dimensional array with initializer");
elt_init = build_vec_init (build1 (INDIRECT_REF, type, base),
! 0, 0, 0);
}
else
elt_init = build_aggr_init (build1 (INDIRECT_REF, type, base),
*** typeck.c.~1~ 2003-01-14 02:21:52.000000000 -0500
--- typeck.c 2003-01-16 17:45:30.000000000 -0500
*************** build_modify_expr (lhs, modifycode, rhs)
*** 5380,5386 ****
from_array = TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
? 1 + (modifycode != INIT_EXPR): 0;
! return build_vec_init (lhs, newrhs, from_array);
}
if (modifycode == INIT_EXPR)
--- 5380,5386 ----
from_array = TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
? 1 + (modifycode != INIT_EXPR): 0;
! return build_vec_init (lhs, NULL_TREE, newrhs, from_array);
}
if (modifycode == INIT_EXPR)