Hi! I've noticed lots of vec_safe_length (CONSTRUCTOR_ELTS (...)) uses in the sources, which IMHO are less readable than the much more often used CONSTRUCTOR_NELTS (...) macro that does the same thing.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2016-09-22 Jakub Jelinek <ja...@redhat.com> * hsa-gen.c (hsa_op_immed::hsa_op_immed Use CONSTRUCTOR_NELTS (...) instead of vec_safe_length (CONSTRUCTOR_ELTS (...)). (gen_hsa_ctor_assignment): Likewise. * print-tree.c (print_node): Likewise. * tree-dump.c (dequeue_and_dump): Likewise. * tree-sra.c (sra_modify_constructor_assign): Likewise. * expr.c (store_constructor): Likewise. * fold-const.c (operand_equal_p): Likewise. * tree-pretty-print.c (dump_generic_node): Likewise. * hsa-brig.c (hsa_op_immed::emit_to_buffer): Likewise. * ipa-icf-gimple.c (func_checker::compare_operand): Likewise. cp/ * typeck2.c (process_init_constructor_record): Use CONSTRUCTOR_NELTS (...) instead of vec_safe_length (CONSTRUCTOR_ELTS (...)). * decl.c (reshape_init_r): Likewise. (check_initializer): Likewise. ada/ * gcc-interface/decl.c (gnat_to_gnu_entity): Use CONSTRUCTOR_NELTS (...) instead of vec_safe_length (CONSTRUCTOR_ELTS (...)). --- gcc/hsa-gen.c.jj 2016-09-16 22:19:42.000000000 +0200 +++ gcc/hsa-gen.c 2016-09-22 17:51:23.078131950 +0200 @@ -1100,8 +1100,7 @@ hsa_op_immed::hsa_op_immed (tree tree_va /* Verify that all elements of a constructor are constants. */ if (TREE_CODE (m_tree_value) == CONSTRUCTOR) - for (unsigned i = 0; - i < vec_safe_length (CONSTRUCTOR_ELTS (m_tree_value)); i++) + for (unsigned i = 0; i < CONSTRUCTOR_NELTS (m_tree_value); i++) { tree v = CONSTRUCTOR_ELT (m_tree_value, i)->value; if (!CONSTANT_CLASS_P (v)) @@ -2845,7 +2844,7 @@ void gen_hsa_ctor_assignment (hsa_op_address *addr_lhs, tree rhs, hsa_bb *hbb, BrigAlignment8_t align) { - if (vec_safe_length (CONSTRUCTOR_ELTS (rhs))) + if (CONSTRUCTOR_NELTS (rhs)) { HSA_SORRY_AT (EXPR_LOCATION (rhs), "support for HSA does not implement load from constructor"); --- gcc/print-tree.c.jj 2016-09-21 08:54:18.000000000 +0200 +++ gcc/print-tree.c 2016-09-22 17:52:19.644409569 +0200 @@ -841,7 +841,7 @@ print_node (FILE *file, const char *pref { unsigned HOST_WIDE_INT cnt; tree index, value; - len = vec_safe_length (CONSTRUCTOR_ELTS (node)); + len = CONSTRUCTOR_NELTS (node); fprintf (file, " lngt %d", len); FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (node), cnt, index, value) --- gcc/tree-dump.c.jj 2016-01-04 14:55:53.000000000 +0100 +++ gcc/tree-dump.c 2016-09-22 17:52:39.430156894 +0200 @@ -646,7 +646,7 @@ dequeue_and_dump (dump_info_p di) { unsigned HOST_WIDE_INT cnt; tree index, value; - dump_int (di, "lngt", vec_safe_length (CONSTRUCTOR_ELTS (t))); + dump_int (di, "lngt", CONSTRUCTOR_NELTS (t)); FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t), cnt, index, value) { dump_child ("idx", index); --- gcc/tree-sra.c.jj 2016-09-16 22:19:42.000000000 +0200 +++ gcc/tree-sra.c 2016-09-22 17:53:37.367417004 +0200 @@ -3224,7 +3224,7 @@ sra_modify_constructor_assign (gimple *s return SRA_AM_MODIFIED; } - if (vec_safe_length (CONSTRUCTOR_ELTS (gimple_assign_rhs1 (stmt))) > 0) + if (CONSTRUCTOR_NELTS (gimple_assign_rhs1 (stmt)) > 0) { /* I have never seen this code path trigger but if it can happen the following should handle it gracefully. */ --- gcc/expr.c.jj 2016-09-16 22:19:40.000000000 +0200 +++ gcc/expr.c 2016-09-22 17:49:51.441302202 +0200 @@ -6187,8 +6187,7 @@ store_constructor (tree exp, rtx target, register whose mode size isn't equal to SIZE since clear_storage can't handle this case. */ else if (size > 0 - && (((int)vec_safe_length (CONSTRUCTOR_ELTS (exp)) - != fields_length (type)) + && (((int) CONSTRUCTOR_NELTS (exp) != fields_length (type)) || mostly_zeros_p (exp)) && (!REG_P (target) || ((HOST_WIDE_INT) GET_MODE_SIZE (GET_MODE (target)) --- gcc/fold-const.c.jj 2016-09-16 22:19:38.000000000 +0200 +++ gcc/fold-const.c 2016-09-22 17:50:34.154756728 +0200 @@ -2954,8 +2954,7 @@ operand_equal_p (const_tree arg0, const_ case CONSTRUCTOR: /* In GIMPLE empty constructors are allowed in initializers of aggregates. */ - return (!vec_safe_length (CONSTRUCTOR_ELTS (arg0)) - && !vec_safe_length (CONSTRUCTOR_ELTS (arg1))); + return !CONSTRUCTOR_NELTS (arg0) && !CONSTRUCTOR_NELTS (arg1); default: break; } --- gcc/tree-pretty-print.c.jj 2016-09-16 22:19:38.000000000 +0200 +++ gcc/tree-pretty-print.c 2016-09-22 17:53:17.397672028 +0200 @@ -1983,7 +1983,7 @@ dump_generic_node (pretty_printer *pp, t dump_decl_name (pp, val, flags); else dump_generic_node (pp, val, spc, flags, false); - if (ix != vec_safe_length (CONSTRUCTOR_ELTS (node)) - 1) + if (ix != CONSTRUCTOR_NELTS (node) - 1) { pp_comma (pp); pp_space (pp); --- gcc/hsa-brig.c.jj 2016-04-22 18:21:54.000000000 +0200 +++ gcc/hsa-brig.c 2016-09-22 17:50:51.828531025 +0200 @@ -985,7 +985,7 @@ hsa_op_immed::emit_to_buffer (unsigned * } else if (TREE_CODE (m_tree_value) == CONSTRUCTOR) { - unsigned len = vec_safe_length (CONSTRUCTOR_ELTS (m_tree_value)); + unsigned len = CONSTRUCTOR_NELTS (m_tree_value); for (unsigned i = 0; i < len; i++) { tree v = CONSTRUCTOR_ELT (m_tree_value, i)->value; --- gcc/ipa-icf-gimple.c.jj 2016-04-22 18:21:29.000000000 +0200 +++ gcc/ipa-icf-gimple.c 2016-09-22 17:51:48.201811107 +0200 @@ -406,8 +406,8 @@ func_checker::compare_operand (tree t1, { case CONSTRUCTOR: { - unsigned length1 = vec_safe_length (CONSTRUCTOR_ELTS (t1)); - unsigned length2 = vec_safe_length (CONSTRUCTOR_ELTS (t2)); + unsigned length1 = CONSTRUCTOR_NELTS (t1); + unsigned length2 = CONSTRUCTOR_NELTS (t2); if (length1 != length2) return return_false (); --- gcc/cp/typeck2.c.jj 2016-07-16 10:41:04.000000000 +0200 +++ gcc/cp/typeck2.c 2016-09-22 17:56:20.391335100 +0200 @@ -1379,7 +1379,7 @@ process_init_constructor_record (tree ty if (type == error_mark_node) return PICFLAG_ERRONEOUS; - if (idx < vec_safe_length (CONSTRUCTOR_ELTS (init))) + if (idx < CONSTRUCTOR_NELTS (init)) { constructor_elt *ce = &(*CONSTRUCTOR_ELTS (init))[idx]; if (ce->index) @@ -1476,7 +1476,7 @@ process_init_constructor_record (tree ty CONSTRUCTOR_APPEND_ELT (v, field, next); } - if (idx < vec_safe_length (CONSTRUCTOR_ELTS (init))) + if (idx < CONSTRUCTOR_NELTS (init)) { if (complain & tf_error) error ("too many initializers for %qT", type); --- gcc/cp/decl.c.jj 2016-09-22 17:55:40.797840730 +0200 +++ gcc/cp/decl.c 2016-09-22 17:55:53.913673234 +0200 @@ -5948,7 +5948,7 @@ reshape_init_r (tree type, reshape_iter element (as allowed by [dcl.init.string]). */ if (!first_initializer_p && TREE_CODE (str_init) == CONSTRUCTOR - && vec_safe_length (CONSTRUCTOR_ELTS (str_init)) == 1) + && CONSTRUCTOR_NELTS (str_init) == 1) { str_init = (*CONSTRUCTOR_ELTS (str_init))[0].value; } @@ -6162,7 +6162,7 @@ check_initializer (tree decl, tree init, if (init && BRACE_ENCLOSED_INITIALIZER_P (init)) { - int init_len = vec_safe_length (CONSTRUCTOR_ELTS (init)); + int init_len = CONSTRUCTOR_NELTS (init); if (SCALAR_TYPE_P (type)) { if (init_len == 0) --- gcc/ada/gcc-interface/decl.c.jj 2016-07-14 20:28:31.000000000 +0200 +++ gcc/ada/gcc-interface/decl.c 2016-09-22 17:57:01.752806892 +0200 @@ -1339,7 +1339,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit = TREE_TYPE (DECL_CHAIN (TYPE_FIELDS (gnu_alloc_type))); if (TREE_CODE (gnu_expr) == CONSTRUCTOR - && vec_safe_length (CONSTRUCTOR_ELTS (gnu_expr)) == 1) + && CONSTRUCTOR_NELTS (gnu_expr) == 1) gnu_expr = NULL_TREE; else gnu_expr Jakub