aboutsummaryrefslogtreecommitdiff
path: root/gcc/expr.c
diff options
context:
space:
mode:
authorGiovanni Bajo <giovannibajo@libero.it>2005-07-20 01:19:59 +0000
committerGiovanni Bajo <giovannibajo@libero.it>2005-07-20 01:19:59 +0000
commit0991dbb37374a89269389d4918eacc7eefa7cdfd (patch)
treecee4baf52782472c6ce30e28249d2a5df154551f /gcc/expr.c
parent71efb5c37550ef6db31122a65a792c1b5af5ae76 (diff)
Make CONSTRUCTOR use VEC to store initializers.
* c-common.c (complete_array_type): Update to cope with VEC in CONSTRUCTOR_ELTS. * c-pretty-print.c (pp_c_initializer_list): Use pp_c_constructor_elts. (pp_c_constructor_elts): New function. * c-pretty-print.h (pp_c_constructor_elts): Declare. * c-typeck.c (build_function_call, build_c_cast, digest_init, struct constructor_stack, struct initializer_stack, constructor_elements, push_init_level, pop_init_level, add_pending_init, find_init_member, output_init_element): Update to cope with VEC in CONSTRUCTOR_ELTS. * coverage.c (build_fn_info_value, build_ctr_info_value, build_gcov_info): Likewise. * expr.c (categorize_ctor_elements_1, store_constructor, expand_expr_real_1): Likewise. * fold-const.c (fold_ternary): Likewise. * gimplify.c (gimplify_init_ctor_preeval, zero_sized_field_decl, gimplify_init_constructor, gimplify_expr): Likewise. * tree-dump.c (dequeue_and_dump): Likewise. * tree-inline.c (copy_tree_r): Add code to duplicate a CONSTRUCTOR node. * tree-pretty-print.c (dump_generic_node): Update to cope with VEC in CONSTRUCTOR_ELTS. * tree-sra.c (generate_element_init_1): Likewise. * tree-ssa-ccp.c (fold_const_aggregate_ref): Likewise. * tree-ssa-operands.c (get_expr_operands): Likewise. * tree-vect-generic.c (expand_vector_piecewise): Likewise. * tree-vect-transform.c (vect_get_vec_def_for_operand): (get_initial_def_for_reduction): Likewise. * tree-vn.c (set_value_handle, get_value_handle): CONSTURCTOR uses value handle in annotations. * tree.c (tree_node_kind, tree_code_size, make_node_stat, tree_node_structure): Add support for constr_kind. (build_vector_from_ctor, build_constructor_single, build_constructor_from_list): New functions. (build_constructor): Update to take a VEC instead of a TREE_LIST. (simple_cst_equal, iterative_hash_expr, initializer_zerop, walk_tree): Update to cope with VEC in CONSTRUCTOR_ELTS. * tree.def (CONSTRUCTOR): Make it a tcc_exceptional node. * tree.h (FOR_EACH_CONSTRUCTOR_VALUE, FOR_EACH_CONSTRUCTOR_ELT, CONSTRUCTOR_APPEND_ELT): New macros. (struct constructor_elt, struct tree_constructor): New data types. (union tree_node): Add tree_constructor field. * treestruct.def: Define TS_CONSTRUCTOR. * varasm.c (const_hash_1, compare_constant, copy_constant, compute_reloc_for_constant, output_addressed_constants, initializer_constant_valid_p, output_constant, array_size_for_constructor, output_constructor): Update to cope with VEC in CONSTRUCTOR_ELTS. * vec.h (VEC_empty, VEC_copy): New macros. ada/ Make CONSTRUCTOR use VEC to store initializers. * decl.c (gnat_to_gnu_entity): Update to cope with VEC in CONSTRUCTOR_ELTS. * trans.c (extract_values): Likewise. * utils.c (convert, remove_conversions): Likewise. * utils2.c (contains_save_expr_p, build_binary_op, build_unary_op, gnat_build_constructor): Likewise. cp/ Make CONSTRUCTOR use VEC to store initializers. * call.c (convert_default_arg): Update call to digest_init. * class.c (dump_class_hierarchy, dump_array): Update to cope with VEC in CONSTRUCTOR_ELTS. * cp-tree.h (EMPTY_CONSTRUCTOR_P): Likewise. (finish_compound_literal, digest_init): Update declaration. * decl.c (struct reshape_iter): New data type. (reshape_init_array): Rename to... (reshape_init_array_1): Update to cope with VEC in CONSTRUCTOR_ELTS. (reshape_init): Rewrite from scratch. Split parts into... (reshape_init_array, reshape_init_vector, reshape_init_class, reshape_init_r): New functions. (check_initializer): Update call to reshape_init. Remove obsolete code. (initialize_artificial_var, cp_complete_array_type): Update to cope with VEC in CONSTRUCTOR_ELTS. * decl2.c (grokfield): Update calls to digest_init. (mark_vtable_entries): Update to cope with VEC in CONSTRUCTOR_ELTS. * error.c (dump_expr_init_vec): New function. (dump_expr): Use dump_expr_init_vec. * init.c (build_zero_init, build_vec_init): Update to cope with VEC in CONSTRUCTOR_ELTS. (expand_default_init): Update call to digest_init. * parser.c (cp_parser_postfix_expression): Use a VEC for the initializers. (cp_parser_initializer_list): Build a VEC of initializers. * pt.c (tsubst_copy, tsubst_copy_and_build): Update to cope with VEC in CONSTRUCTOR_ELTS. * rtti.c (tinfo_base_init, generic_initializer, ptr_initializer, ptm_initializer, class_initializer, get_pseudo_ti_init): Use build_constructor_from_list instead of build_constructor. * semantics.c (finish_compound_literal): Update call to digest_init. * tree.c (stabilize_init): Update to cope with VEC in CONSTRUCTOR_ELTS. * typeck.c (build_ptrmemfunc1): Likewise. * typeck2.c: (cxx_incomplete_type_error, split_nonconstant_init_1): Likewise. (store_init_value): Use build_constructor_from_list and update call to digest_init. (digest_init): Rewrite. (process_init_constructor): Rewrite from scratch. Split into... (process_init_constructor_array, picflag_from_initializer, process_init_constructor_record, process_init_constructor_union): New functions. (PICFLAG_ERRONEOUS, PICFLAG_NOT_ALL_CONSTANT, PICFLAG_NOT_ALL_SIMPLE): New macros. (build_functional_cast): Use build_constructor_from_list instead of build_constructor. fortran/ Make CONSTRUCTOR use VEC to store initializers. * trans-array.c (gfc_build_null_descriptor, gfc_trans_array_constructor_value, gfc_conv_array_initializer): Update to cope with VEC in CONSTRUCTOR_ELTS. * trans-common.c (create_common): Likewise. * trans-expr.c (gfc_conv_structure): Likewise. * trans-stmt.c (gfc_trans_character_select): Use build_constructor_from_list instead of build_constructor. java/ Make CONSTRUCTOR use VEC to store initializers. * check-init.c (check_init): Update to cope with VEC in CONSTRUCTOR_ELTS. * class.c (make_field_value, make_method_value, get_dispatch_table, make_class_data, emit_symbol_table, emit_catch_table, emit_assertion_table): Use build_constructor_from_list instead of build_constructor. * constants.c (build_constants_constructor): Likewise. * java-gimplify.c (java_gimplify_new_array_init): Update to cope with VEC in CONSTRUCTOR_ELTS. * java-tree.h (START_RECORD_CONSTRUCTOR, PUSH_SUPER_VALUE, PUSH_FIELD_VALUE, FINISH_RECORD_CONSTRUCTOR): Create a VEC instead of a TREE_LIST. * jcf-write.c (generate_bytecode_insns): Update to cope with VEC in CONSTRUCTOR_ELTS. * parse.y (build_new_array_init): Use build_constructor_from_list instead of build_constructor. (patch_new_array_init): Update to cope with VEC in CONSTRUCTOR_ELTS. (array_constructor_check_entry): Likewise. objc/ Make CONSTRUCTOR use VEC to store initializers. * objc-act.c (objc_build_constructor): Use build_constructor_from_list instead of build_constructor. testsuite/ Make CONSTRUCTOR use VEC to store initializers. * g++.dg/ext/complit3.C: Check for specific error messages. * g++.dg/init/brace2.C: Update error message. * g++.dg/warn/Wbraces2.C: Likewise. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@102182 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/expr.c')
-rw-r--r--gcc/expr.c158
1 files changed, 78 insertions, 80 deletions
diff --git a/gcc/expr.c b/gcc/expr.c
index 182ab2382be..60d45f3ad25 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -4398,17 +4398,16 @@ categorize_ctor_elements_1 (tree ctor, HOST_WIDE_INT *p_nz_elts,
HOST_WIDE_INT *p_elt_count,
bool *p_must_clear)
{
+ unsigned HOST_WIDE_INT idx;
HOST_WIDE_INT nz_elts, nc_elts, elt_count;
- tree list;
+ tree value, purpose;
nz_elts = 0;
nc_elts = 0;
elt_count = 0;
- for (list = CONSTRUCTOR_ELTS (ctor); list; list = TREE_CHAIN (list))
+ FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (ctor), idx, purpose, value)
{
- tree value = TREE_VALUE (list);
- tree purpose = TREE_PURPOSE (list);
HOST_WIDE_INT mult;
mult = 1;
@@ -4482,14 +4481,16 @@ categorize_ctor_elements_1 (tree ctor, HOST_WIDE_INT *p_nz_elts,
tree init_sub_type;
bool clear_this = true;
- list = CONSTRUCTOR_ELTS (ctor);
- if (list)
+ if (!VEC_empty (constructor_elt, CONSTRUCTOR_ELTS (ctor)))
{
/* We don't expect more than one element of the union to be
initialized. Not sure what we should do otherwise... */
- gcc_assert (TREE_CHAIN (list) == NULL);
+ gcc_assert (VEC_length (constructor_elt, CONSTRUCTOR_ELTS (ctor))
+ == 1);
- init_sub_type = TREE_TYPE (TREE_VALUE (list));
+ init_sub_type = TREE_TYPE (VEC_index (constructor_elt,
+ CONSTRUCTOR_ELTS (ctor),
+ 0)->value);
/* ??? We could look at each element of the union, and find the
largest element. Which would avoid comparing the size of the
@@ -4699,7 +4700,8 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
case UNION_TYPE:
case QUAL_UNION_TYPE:
{
- tree elt;
+ unsigned HOST_WIDE_INT idx;
+ tree field, value;
/* If size is zero or the target is already cleared, do nothing. */
if (size == 0 || cleared)
@@ -4731,7 +4733,7 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
register whose mode size isn't equal to SIZE since
clear_storage can't handle this case. */
else if (size > 0
- && ((list_length (CONSTRUCTOR_ELTS (exp))
+ && (((int)VEC_length (constructor_elt, CONSTRUCTOR_ELTS (exp))
!= fields_length (type))
|| mostly_zeros_p (exp))
&& (!REG_P (target)
@@ -4747,11 +4749,8 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
/* Store each element of the constructor into the
corresponding field of TARGET. */
-
- for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
+ FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, field, value)
{
- tree field = TREE_PURPOSE (elt);
- tree value = TREE_VALUE (elt);
enum machine_mode mode;
HOST_WIDE_INT bitsize;
HOST_WIDE_INT bitpos = 0;
@@ -4857,8 +4856,8 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
}
case ARRAY_TYPE:
{
- tree elt;
- int i;
+ tree value, index;
+ unsigned HOST_WIDE_INT i;
int need_to_clear;
tree domain;
tree elttype = TREE_TYPE (type);
@@ -4888,18 +4887,20 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
need_to_clear = 1;
else
{
+ unsigned HOST_WIDE_INT idx;
+ tree index, value;
HOST_WIDE_INT count = 0, zero_count = 0;
need_to_clear = ! const_bounds_p;
/* This loop is a more accurate version of the loop in
mostly_zeros_p (it handles RANGE_EXPR in an index). It
is also needed to check for missing elements. */
- for (elt = CONSTRUCTOR_ELTS (exp);
- elt != NULL_TREE && ! need_to_clear;
- elt = TREE_CHAIN (elt))
+ FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), idx, index, value)
{
- tree index = TREE_PURPOSE (elt);
HOST_WIDE_INT this_node_count;
+
+ if (need_to_clear)
+ break;
if (index != NULL_TREE && TREE_CODE (index) == RANGE_EXPR)
{
@@ -4920,7 +4921,7 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
this_node_count = 1;
count += this_node_count;
- if (mostly_zeros_p (TREE_VALUE (elt)))
+ if (mostly_zeros_p (value))
zero_count += this_node_count;
}
@@ -4949,16 +4950,12 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
/* Store each element of the constructor into the
corresponding element of TARGET, determined by counting the
elements. */
- for (elt = CONSTRUCTOR_ELTS (exp), i = 0;
- elt;
- elt = TREE_CHAIN (elt), i++)
+ FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), i, index, value)
{
enum machine_mode mode;
HOST_WIDE_INT bitsize;
HOST_WIDE_INT bitpos;
int unsignedp;
- tree value = TREE_VALUE (elt);
- tree index = TREE_PURPOSE (elt);
rtx xtarget = target;
if (cleared && initializer_zerop (value))
@@ -5118,7 +5115,8 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
case VECTOR_TYPE:
{
- tree elt;
+ unsigned HOST_WIDE_INT idx;
+ constructor_elt *ce;
int i;
int need_to_clear;
int icode = 0;
@@ -5158,18 +5156,17 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
else
{
unsigned HOST_WIDE_INT count = 0, zero_count = 0;
+ tree value;
- for (elt = CONSTRUCTOR_ELTS (exp);
- elt != NULL_TREE;
- elt = TREE_CHAIN (elt))
+ FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
{
int n_elts_here = tree_low_cst
(int_const_binop (TRUNC_DIV_EXPR,
- TYPE_SIZE (TREE_TYPE (TREE_VALUE (elt))),
+ TYPE_SIZE (TREE_TYPE (value)),
TYPE_SIZE (elttype), 0), 1);
count += n_elts_here;
- if (mostly_zeros_p (TREE_VALUE (elt)))
+ if (mostly_zeros_p (value))
zero_count += n_elts_here;
}
@@ -5193,20 +5190,19 @@ store_constructor (tree exp, rtx target, int cleared, HOST_WIDE_INT size)
/* Store each element of the constructor into the corresponding
element of TARGET, determined by counting the elements. */
- for (elt = CONSTRUCTOR_ELTS (exp), i = 0;
- elt;
- elt = TREE_CHAIN (elt), i += bitsize / elt_size)
+ for (idx = 0, i = 0;
+ VEC_iterate (constructor_elt, CONSTRUCTOR_ELTS (exp), idx, ce);
+ idx++, i += bitsize / elt_size)
{
- tree value = TREE_VALUE (elt);
- tree index = TREE_PURPOSE (elt);
HOST_WIDE_INT eltpos;
+ tree value = ce->value;
bitsize = tree_low_cst (TYPE_SIZE (TREE_TYPE (value)), 1);
if (cleared && initializer_zerop (value))
continue;
- if (index != 0)
- eltpos = tree_low_cst (index, 1);
+ if (ce->index)
+ eltpos = tree_low_cst (ce->index, 1);
else
eltpos = i;
@@ -6733,8 +6729,9 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
|| GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (exp))) == MODE_VECTOR_FLOAT)
return const_vector_from_tree (exp);
else
- return expand_expr (build1 (CONSTRUCTOR, TREE_TYPE (exp),
- TREE_VECTOR_CST_ELTS (exp)),
+ return expand_expr (build_constructor_from_list
+ (TREE_TYPE (exp),
+ TREE_VECTOR_CST_ELTS (exp)),
ignore ? const0_rtx : target, tmode, modifier);
case CONST_DECL:
@@ -6832,10 +6829,11 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
subexpressions. */
if (ignore)
{
- tree elt;
+ unsigned HOST_WIDE_INT idx;
+ tree value;
- for (elt = CONSTRUCTOR_ELTS (exp); elt; elt = TREE_CHAIN (elt))
- expand_expr (TREE_VALUE (elt), const0_rtx, VOIDmode, 0);
+ FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (exp), idx, value)
+ expand_expr (value, const0_rtx, VOIDmode, 0);
return const0_rtx;
}
@@ -6997,16 +6995,17 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
&& ! TREE_SIDE_EFFECTS (array)
&& TREE_CODE (index) == INTEGER_CST)
{
- tree elem;
-
- for (elem = CONSTRUCTOR_ELTS (array);
- (elem && !tree_int_cst_equal (TREE_PURPOSE (elem), index));
- elem = TREE_CHAIN (elem))
- ;
+ unsigned HOST_WIDE_INT ix;
+ tree field, value;
- if (elem && !TREE_SIDE_EFFECTS (TREE_VALUE (elem)))
- return expand_expr (fold (TREE_VALUE (elem)), target, tmode,
- modifier);
+ FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (array), ix,
+ field, value)
+ if (tree_int_cst_equal (field, index))
+ {
+ if (!TREE_SIDE_EFFECTS (value))
+ return expand_expr (fold (value), target, tmode, modifier);
+ break;
+ }
}
else if (optimize >= 1
@@ -7024,17 +7023,18 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
if (TREE_CODE (init) == CONSTRUCTOR)
{
- tree elem;
-
- for (elem = CONSTRUCTOR_ELTS (init);
- (elem
- && !tree_int_cst_equal (TREE_PURPOSE (elem), index));
- elem = TREE_CHAIN (elem))
- ;
-
- if (elem && !TREE_SIDE_EFFECTS (TREE_VALUE (elem)))
- return expand_expr (fold (TREE_VALUE (elem)), target,
- tmode, modifier);
+ unsigned HOST_WIDE_INT ix;
+ tree field, value;
+
+ FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix,
+ field, value)
+ if (tree_int_cst_equal (field, index))
+ {
+ if (!TREE_SIDE_EFFECTS (value))
+ return expand_expr (fold (value), target, tmode,
+ modifier);
+ break;
+ }
}
else if (TREE_CODE (init) == STRING_CST
&& 0 > compare_tree_int (index,
@@ -7058,11 +7058,12 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
appropriate field if it is present. */
if (TREE_CODE (TREE_OPERAND (exp, 0)) == CONSTRUCTOR)
{
- tree elt;
+ unsigned HOST_WIDE_INT idx;
+ tree field, value;
- for (elt = CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0)); elt;
- elt = TREE_CHAIN (elt))
- if (TREE_PURPOSE (elt) == TREE_OPERAND (exp, 1)
+ FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0)),
+ idx, field, value)
+ if (field == TREE_OPERAND (exp, 1)
/* We can normally use the value of the field in the
CONSTRUCTOR. However, if this is a bitfield in
an integral mode that we can fit in a HOST_WIDE_INT,
@@ -7070,24 +7071,21 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
since this is done implicitly by the constructor. If
the bitfield does not meet either of those conditions,
we can't do this optimization. */
- && (! DECL_BIT_FIELD (TREE_PURPOSE (elt))
- || ((GET_MODE_CLASS (DECL_MODE (TREE_PURPOSE (elt)))
- == MODE_INT)
- && (GET_MODE_BITSIZE (DECL_MODE (TREE_PURPOSE (elt)))
+ && (! DECL_BIT_FIELD (field)
+ || ((GET_MODE_CLASS (DECL_MODE (field)) == MODE_INT)
+ && (GET_MODE_BITSIZE (DECL_MODE (field))
<= HOST_BITS_PER_WIDE_INT))))
{
- if (DECL_BIT_FIELD (TREE_PURPOSE (elt))
+ if (DECL_BIT_FIELD (field)
&& modifier == EXPAND_STACK_PARM)
target = 0;
- op0 = expand_expr (TREE_VALUE (elt), target, tmode, modifier);
- if (DECL_BIT_FIELD (TREE_PURPOSE (elt)))
+ op0 = expand_expr (value, target, tmode, modifier);
+ if (DECL_BIT_FIELD (field))
{
- HOST_WIDE_INT bitsize
- = TREE_INT_CST_LOW (DECL_SIZE (TREE_PURPOSE (elt)));
- enum machine_mode imode
- = TYPE_MODE (TREE_TYPE (TREE_PURPOSE (elt)));
+ HOST_WIDE_INT bitsize = TREE_INT_CST_LOW (DECL_SIZE (field));
+ enum machine_mode imode = TYPE_MODE (TREE_TYPE (field));
- if (TYPE_UNSIGNED (TREE_TYPE (TREE_PURPOSE (elt))))
+ if (TYPE_UNSIGNED (TREE_TYPE (field)))
{
op1 = GEN_INT (((HOST_WIDE_INT) 1 << bitsize) - 1);
op0 = expand_and (imode, op0, op1, target);