Skip to content

Commit

Permalink
gcc/: Rename array_type_nelts => array_type_nelts_minus_one
Browse files Browse the repository at this point in the history
The old name was misleading.

While at it, also rename some temporary variables that are used with
this function, for consistency.

Link: <https://inbox.sourceware.org/gcc-patches/[email protected]/T/#m2f661c67c8f7b2c405c8c7fc3152dd85dc729120>

gcc/ChangeLog:

	* tree.cc (array_type_nelts, array_type_nelts_minus_one)
	* tree.h (array_type_nelts, array_type_nelts_minus_one)
	* expr.cc (count_type_elements)
	* config/aarch64/aarch64.cc
	(pure_scalable_type_info::analyze_array)
	* config/i386/i386.cc (ix86_canonical_va_list_type):
	Rename array_type_nelts => array_type_nelts_minus_one
	The old name was misleading.

gcc/c/ChangeLog:

	* c-decl.cc (one_element_array_type_p, get_parm_array_spec)
	* c-fold.cc (c_fold_array_ref):
	Rename array_type_nelts => array_type_nelts_minus_one

gcc/cp/ChangeLog:

	* decl.cc (reshape_init_array)
	* init.cc
	(build_zero_init_1)
	(build_value_init_noctor)
	(build_vec_init)
	(build_delete)
	* lambda.cc (add_capture)
	* tree.cc (array_type_nelts_top):
	Rename array_type_nelts => array_type_nelts_minus_one

gcc/fortran/ChangeLog:

	* trans-array.cc (structure_alloc_comps)
	* trans-openmp.cc
	(gfc_walk_alloc_comps)
	(gfc_omp_clause_linear_ctor):
	Rename array_type_nelts => array_type_nelts_minus_one

gcc/rust/ChangeLog:

	* backend/rust-tree.cc (array_type_nelts_top):
	Rename array_type_nelts => array_type_nelts_minus_one

Suggested-by: Richard Biener <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
  • Loading branch information
alejandro-colomar authored and jsm28 committed Oct 18, 2024
1 parent f8687bc commit 1157765
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 28 deletions.
10 changes: 5 additions & 5 deletions gcc/c/c-decl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5367,7 +5367,7 @@ one_element_array_type_p (const_tree type)
{
if (TREE_CODE (type) != ARRAY_TYPE)
return false;
return integer_zerop (array_type_nelts (type));
return integer_zerop (array_type_nelts_minus_one (type));
}

/* Determine whether TYPE is a zero-length array type "[0]". */
Expand Down Expand Up @@ -6315,15 +6315,15 @@ get_parm_array_spec (const struct c_parm *parm, tree attrs)
for (tree type = parm->specs->type; TREE_CODE (type) == ARRAY_TYPE;
type = TREE_TYPE (type))
{
tree nelts = array_type_nelts (type);
if (error_operand_p (nelts))
tree nelts_minus_one = array_type_nelts_minus_one (type);
if (error_operand_p (nelts_minus_one))
return attrs;
if (TREE_CODE (nelts) != INTEGER_CST)
if (TREE_CODE (nelts_minus_one) != INTEGER_CST)
{
/* Each variable VLA bound is represented by the dollar
sign. */
spec += "$";
tpbnds = tree_cons (NULL_TREE, nelts, tpbnds);
tpbnds = tree_cons (NULL_TREE, nelts_minus_one, tpbnds);
}
}
tpbnds = nreverse (tpbnds);
Expand Down
7 changes: 4 additions & 3 deletions gcc/c/c-fold.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ c_fold_array_ref (tree type, tree ary, tree index)
unsigned elem_nchars = (TYPE_PRECISION (elem_type)
/ TYPE_PRECISION (char_type_node));
unsigned len = (unsigned) TREE_STRING_LENGTH (ary) / elem_nchars;
tree nelts = array_type_nelts (TREE_TYPE (ary));
tree nelts_minus_one = array_type_nelts_minus_one (TREE_TYPE (ary));
bool dummy1 = true, dummy2 = true;
nelts = c_fully_fold_internal (nelts, true, &dummy1, &dummy2, false, false);
nelts_minus_one = c_fully_fold_internal (nelts_minus_one, true, &dummy1,
&dummy2, false, false);
unsigned HOST_WIDE_INT i = tree_to_uhwi (index);
if (!tree_int_cst_le (index, nelts)
if (!tree_int_cst_le (index, nelts_minus_one)
|| i >= len
|| i + elem_nchars > len)
return NULL_TREE;
Expand Down
2 changes: 1 addition & 1 deletion gcc/config/aarch64/aarch64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ pure_scalable_type_info::analyze_array (const_tree type)

/* An array of unknown, flexible or variable length will be passed and
returned by reference whatever we do. */
tree nelts_minus_one = array_type_nelts (type);
tree nelts_minus_one = array_type_nelts_minus_one (type);
if (!tree_fits_uhwi_p (nelts_minus_one))
return DOESNT_MATTER;

Expand Down
2 changes: 1 addition & 1 deletion gcc/config/i386/i386.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24629,7 +24629,7 @@ ix86_canonical_va_list_type (tree type)
return ms_va_list_type_node;

if ((TREE_CODE (type) == ARRAY_TYPE
&& integer_zerop (array_type_nelts (type)))
&& integer_zerop (array_type_nelts_minus_one (type)))
|| POINTER_TYPE_P (type))
{
tree elem_type = TREE_TYPE (type);
Expand Down
2 changes: 1 addition & 1 deletion gcc/cp/decl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6956,7 +6956,7 @@ reshape_init_array (tree type, reshape_iter *d, tree first_initializer_p,
gcc_assert (TREE_CODE (type) == ARRAY_TYPE);

if (TYPE_DOMAIN (type))
max_index = array_type_nelts (type);
max_index = array_type_nelts_minus_one (type);

return reshape_init_array_1 (TREE_TYPE (type), max_index, d,
first_initializer_p, complain);
Expand Down
8 changes: 4 additions & 4 deletions gcc/cp/init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ build_zero_init_1 (tree type, tree nelts, bool static_storage_p,
else if (TYPE_DOMAIN (type) == NULL_TREE)
return NULL_TREE;
else
max_index = array_type_nelts (type);
max_index = array_type_nelts_minus_one (type);

/* If we have an error_mark here, we should just return error mark
as we don't know the size of the array yet. */
Expand Down Expand Up @@ -474,7 +474,7 @@ build_value_init_noctor (tree type, tsubst_flags_t complain)
vec<constructor_elt, va_gc> *v = NULL;

/* Iterate over the array elements, building initializations. */
tree max_index = array_type_nelts (type);
tree max_index = array_type_nelts_minus_one (type);

/* If we have an error_mark here, we should just return error mark
as we don't know the size of the array yet. */
Expand Down Expand Up @@ -4526,7 +4526,7 @@ build_vec_init (tree base, tree maxindex, tree init,
: location_of (base));

if (TREE_CODE (atype) == ARRAY_TYPE && TYPE_DOMAIN (atype))
maxindex = array_type_nelts (atype);
maxindex = array_type_nelts_minus_one (atype);

if (maxindex == NULL_TREE || maxindex == error_mark_node)
return error_mark_node;
Expand Down Expand Up @@ -5191,7 +5191,7 @@ build_delete (location_t loc, tree otype, tree addr,
error_at (loc, "unknown array size in delete");
return error_mark_node;
}
return build_vec_delete (loc, addr, array_type_nelts (type),
return build_vec_delete (loc, addr, array_type_nelts_minus_one (type),
auto_delete, use_global_delete, complain);
}

Expand Down
3 changes: 2 additions & 1 deletion gcc/cp/lambda.cc
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p,
integer_zero_node, tf_warning_or_error);
initializer = build_constructor_va (init_list_type_node, 2,
NULL_TREE, build_address (elt),
NULL_TREE, array_type_nelts (type));
NULL_TREE,
array_type_nelts_minus_one (type));
type = vla_capture_type (type);
}
else if (!dependent_type_p (type)
Expand Down
2 changes: 1 addition & 1 deletion gcc/cp/tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3085,7 +3085,7 @@ array_type_nelts_top (tree type)
{
return fold_build2_loc (input_location,
PLUS_EXPR, sizetype,
array_type_nelts (type),
array_type_nelts_minus_one (type),
size_one_node);
}

Expand Down
8 changes: 4 additions & 4 deletions gcc/expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6991,14 +6991,14 @@ count_type_elements (const_tree type, bool for_ctor_p)
{
case ARRAY_TYPE:
{
tree nelts;
tree nelts_minus_one;

nelts = array_type_nelts (type);
if (nelts && tree_fits_uhwi_p (nelts))
nelts_minus_one = array_type_nelts_minus_one (type);
if (nelts_minus_one && tree_fits_uhwi_p (nelts_minus_one))
{
unsigned HOST_WIDE_INT n;

n = tree_to_uhwi (nelts) + 1;
n = tree_to_uhwi (nelts_minus_one) + 1;
if (n == 0 || for_ctor_p)
return n;
else
Expand Down
2 changes: 1 addition & 1 deletion gcc/fortran/trans-array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9695,7 +9695,7 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl, tree dest,
else
{
/* Otherwise use the TYPE_DOMAIN information. */
tmp = array_type_nelts (decl_type);
tmp = array_type_nelts_minus_one (decl_type);
tmp = fold_convert (gfc_array_index_type, tmp);
}

Expand Down
4 changes: 2 additions & 2 deletions gcc/fortran/trans-openmp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ gfc_walk_alloc_comps (tree decl, tree dest, tree var,
tem = size_binop (MINUS_EXPR, tem, size_one_node);
}
else
tem = array_type_nelts (type);
tem = array_type_nelts_minus_one (type);
tem = fold_convert (gfc_array_index_type, tem);
}

Expand Down Expand Up @@ -1309,7 +1309,7 @@ gfc_omp_clause_linear_ctor (tree clause, tree dest, tree src, tree add)
nelems = size_binop (MINUS_EXPR, nelems, size_one_node);
}
else
nelems = array_type_nelts (type);
nelems = array_type_nelts_minus_one (type);
nelems = fold_convert (gfc_array_index_type, nelems);

gfc_omp_linear_clause_add_loop (&block, dest, src, add, nelems);
Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/backend/rust-tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ tree
array_type_nelts_top (tree type)
{
return fold_build2_loc (input_location, PLUS_EXPR, sizetype,
array_type_nelts (type), size_one_node);
array_type_nelts_minus_one (type), size_one_node);
}

// forked from gcc/cp/tree.cc builtin_valid_in_constant_expr_p
Expand Down
4 changes: 2 additions & 2 deletions gcc/tree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3701,7 +3701,7 @@ int_byte_position (const_tree field)
ARRAY_TYPE) minus one. This counts only elements of the top array. */

tree
array_type_nelts (const_tree type)
array_type_nelts_minus_one (const_tree type)
{
tree index_type, min, max;

Expand Down Expand Up @@ -14800,7 +14800,7 @@ is_empty_type (const_tree type)
return true;
}
else if (TREE_CODE (type) == ARRAY_TYPE)
return (integer_minus_onep (array_type_nelts (type))
return (integer_minus_onep (array_type_nelts_minus_one (type))
|| TYPE_DOMAIN (type) == NULL_TREE
|| is_empty_type (TREE_TYPE (type)));
return false;
Expand Down
2 changes: 1 addition & 1 deletion gcc/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -4929,7 +4929,7 @@ extern tree build_method_type_directly (tree, tree, tree);
extern tree build_method_type (tree, tree);
extern tree build_offset_type (tree, tree);
extern tree build_complex_type (tree, bool named = false);
extern tree array_type_nelts (const_tree);
extern tree array_type_nelts_minus_one (const_tree);

extern tree value_member (tree, tree);
extern tree purpose_member (const_tree, tree);
Expand Down

0 comments on commit 1157765

Please sign in to comment.