Commit a48cccea by Jason Merrill Committed by Jason Merrill

re PR c++/8564 (ICE in find_function_data, at function.c:329)

        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.

From-SVN: r61422
parent 3d042e77
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.
2003-01-16 Jeffrey D. Oldham <oldham@codesourcery.com> 2003-01-16 Jeffrey D. Oldham <oldham@codesourcery.com>
* cp-tree.h (tsubst_copy_and_build): New declaration. * cp-tree.h (tsubst_copy_and_build): New declaration.
......
...@@ -3957,7 +3957,7 @@ extern tree build_member_call (tree, tree, tree); ...@@ -3957,7 +3957,7 @@ extern tree build_member_call (tree, tree, tree);
extern tree build_offset_ref (tree, tree); extern tree build_offset_ref (tree, tree);
extern tree resolve_offset_ref (tree); extern tree resolve_offset_ref (tree);
extern tree build_new (tree, tree, tree, int); extern tree build_new (tree, tree, tree, int);
extern tree build_vec_init (tree, tree, int); extern tree build_vec_init (tree, tree, tree, int);
extern tree build_x_delete (tree, int, tree); extern tree build_x_delete (tree, int, tree);
extern tree build_delete (tree, tree, special_function_kind, int, int); extern tree build_delete (tree, tree, special_function_kind, int, int);
extern void push_base_cleanups (void); extern void push_base_cleanups (void);
......
...@@ -353,7 +353,8 @@ perform_member_init (tree member, tree init) ...@@ -353,7 +353,8 @@ perform_member_init (tree member, tree init)
&& TREE_CODE (TREE_TYPE (TREE_VALUE (init))) == ARRAY_TYPE) && TREE_CODE (TREE_TYPE (TREE_VALUE (init))) == ARRAY_TYPE)
{ {
/* Initialization of one array from another. */ /* Initialization of one array from another. */
finish_expr_stmt (build_vec_init (decl, TREE_VALUE (init), 1)); finish_expr_stmt (build_vec_init (decl, NULL_TREE, TREE_VALUE (init),
/* from_array=*/1));
} }
else else
finish_expr_stmt (build_aggr_init (decl, init, 0)); finish_expr_stmt (build_aggr_init (decl, init, 0));
...@@ -1115,7 +1116,7 @@ build_aggr_init (exp, init, flags) ...@@ -1115,7 +1116,7 @@ build_aggr_init (exp, init, flags)
TREE_TYPE (exp) = TYPE_MAIN_VARIANT (type); TREE_TYPE (exp) = TYPE_MAIN_VARIANT (type);
if (itype && cp_type_quals (itype) != TYPE_UNQUALIFIED) if (itype && cp_type_quals (itype) != TYPE_UNQUALIFIED)
TREE_TYPE (init) = TYPE_MAIN_VARIANT (itype); TREE_TYPE (init) = TYPE_MAIN_VARIANT (itype);
stmt_expr = build_vec_init (exp, init, stmt_expr = build_vec_init (exp, NULL_TREE, init,
init && same_type_p (TREE_TYPE (init), init && same_type_p (TREE_TYPE (init),
TREE_TYPE (exp))); TREE_TYPE (exp)));
TREE_READONLY (exp) = was_const; TREE_READONLY (exp) = was_const;
...@@ -2155,6 +2156,7 @@ build_new_1 (exp) ...@@ -2155,6 +2156,7 @@ build_new_1 (exp)
tree placement, init; tree placement, init;
tree type, true_type, size, rval, t; tree type, true_type, size, rval, t;
tree full_type; tree full_type;
tree outer_nelts = NULL_TREE;
tree nelts = NULL_TREE; tree nelts = NULL_TREE;
tree alloc_call, alloc_expr, alloc_node; tree alloc_call, alloc_expr, alloc_node;
tree alloc_fn; tree alloc_fn;
...@@ -2184,12 +2186,11 @@ build_new_1 (exp) ...@@ -2184,12 +2186,11 @@ build_new_1 (exp)
if (TREE_CODE (type) == ARRAY_REF) if (TREE_CODE (type) == ARRAY_REF)
{ {
has_array = 1; has_array = 1;
nelts = TREE_OPERAND (type, 1); nelts = outer_nelts = TREE_OPERAND (type, 1);
type = TREE_OPERAND (type, 0); type = TREE_OPERAND (type, 0);
full_type = cp_build_binary_op (MINUS_EXPR, nelts, integer_one_node); /* Use an incomplete array type to avoid VLA headaches. */
full_type = build_index_type (full_type); full_type = build_cplus_array_type (type, NULL_TREE);
full_type = build_cplus_array_type (type, full_type);
} }
else else
full_type = type; full_type = type;
...@@ -2379,7 +2380,11 @@ build_new_1 (exp) ...@@ -2379,7 +2380,11 @@ build_new_1 (exp)
pedwarn ("ISO C++ forbids initialization in array new"); pedwarn ("ISO C++ forbids initialization in array new");
if (has_array) if (has_array)
init_expr = build_vec_init (init_expr, init, 0); 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)) else if (TYPE_NEEDS_CONSTRUCTING (type))
init_expr = build_special_member_call (init_expr, init_expr = build_special_member_call (init_expr,
complete_ctor_identifier, complete_ctor_identifier,
...@@ -2710,6 +2715,9 @@ get_temp_regvar (type, init) ...@@ -2710,6 +2715,9 @@ get_temp_regvar (type, init)
initialization of a vector of aggregate types. initialization of a vector of aggregate types.
BASE is a reference to the vector, of ARRAY_TYPE. 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. INIT is the (possibly NULL) initializer.
FROM_ARRAY is 0 if we should init everything with INIT FROM_ARRAY is 0 if we should init everything with INIT
...@@ -2720,8 +2728,8 @@ get_temp_regvar (type, init) ...@@ -2720,8 +2728,8 @@ get_temp_regvar (type, init)
but use assignment instead of initialization. */ but use assignment instead of initialization. */
tree tree
build_vec_init (base, init, from_array) build_vec_init (base, maxindex, init, from_array)
tree base, init; tree base, init, maxindex;
int from_array; int from_array;
{ {
tree rval; tree rval;
...@@ -2741,9 +2749,11 @@ build_vec_init (base, init, from_array) ...@@ -2741,9 +2749,11 @@ build_vec_init (base, init, from_array)
tree try_block = NULL_TREE; tree try_block = NULL_TREE;
tree try_body = NULL_TREE; tree try_body = NULL_TREE;
int num_initialized_elts = 0; int num_initialized_elts = 0;
tree maxindex = array_type_nelts (TREE_TYPE (base));
if (maxindex == error_mark_node) if (TYPE_DOMAIN (atype))
maxindex = array_type_nelts (atype);
if (maxindex == NULL_TREE || maxindex == error_mark_node)
return error_mark_node; return error_mark_node;
if (init if (init
...@@ -2934,7 +2944,7 @@ build_vec_init (base, init, from_array) ...@@ -2934,7 +2944,7 @@ build_vec_init (base, init, from_array)
sorry sorry
("cannot initialize multi-dimensional array with initializer"); ("cannot initialize multi-dimensional array with initializer");
elt_init = build_vec_init (build1 (INDIRECT_REF, type, base), elt_init = build_vec_init (build1 (INDIRECT_REF, type, base),
0, 0); 0, 0, 0);
} }
else else
elt_init = build_aggr_init (build1 (INDIRECT_REF, type, base), elt_init = build_aggr_init (build1 (INDIRECT_REF, type, base),
......
...@@ -5380,7 +5380,7 @@ build_modify_expr (lhs, modifycode, rhs) ...@@ -5380,7 +5380,7 @@ build_modify_expr (lhs, modifycode, rhs)
from_array = TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE from_array = TREE_CODE (TREE_TYPE (newrhs)) == ARRAY_TYPE
? 1 + (modifycode != INIT_EXPR): 0; ? 1 + (modifycode != INIT_EXPR): 0;
return build_vec_init (lhs, newrhs, from_array); return build_vec_init (lhs, NULL_TREE, newrhs, from_array);
} }
if (modifycode == INIT_EXPR) if (modifycode == INIT_EXPR)
......
// Test that new-expressions at file scope work properly.
struct A { static char* p; };
int i = 1;
char* A::p = new char[i];
void foo() {}
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