From patchwork Wed Oct 2 09:41:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 1991906 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=eXVXpZqL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XJVFq1gZcz1xtY for ; Wed, 2 Oct 2024 19:42:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 080D13850204 for ; Wed, 2 Oct 2024 09:42:05 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by sourceware.org (Postfix) with ESMTPS id 1E8EB3860C34 for ; Wed, 2 Oct 2024 09:41:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1E8EB3860C34 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=kernel.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1E8EB3860C34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2604:1380:4641:c500::1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727862099; cv=none; b=T1IoYt0QiO1jvob+5TrMaw9+9JAXHHRmuFFApLkWsaP+Gc7+3e/tNzbO5kq8287CYstfNqGjay1by1yUd/5H3zEegDqgoPjm4WJNDGGCDU9jC3ql9GzahJzFBs9CxmR5XKzFdtRCSRO/KM4nGP5TSF9Ronp1VBiFiahWzbMLavI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727862099; c=relaxed/simple; bh=i5qn3iGrVQZb5jOcwpvwRg4MVuHErRBlX70GVZmVOzc=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=Qul1PJnmMZ9r/lA7/omDfgWbRpPGe975a7Y5tJvMEbUyAgzjU5CyYpW80y3j+VwzsNWaCdn9WuoDFfuJ3r5sdi//WqukmMZk7SV8l6fN3SREytAGL9fIIStgV1XaPwhM4xcP1ew6EsSLgWg+5f6P2zKG3N4mY8OCbwGkpNgZBjc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 7C0CD5C34D7; Wed, 2 Oct 2024 09:41:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D313C4CEC5; Wed, 2 Oct 2024 09:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727862096; bh=i5qn3iGrVQZb5jOcwpvwRg4MVuHErRBlX70GVZmVOzc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eXVXpZqLmoKjNK2uwaa334ld6ckBY5mpYV0MncW0us+myQJRy7OfFhGslN/jHGzzW E9uc4Tb29vx1TY8jgqFJkG6jYN79SBiYXSyUdwbgQKVm48nZgNNO1iCNZqRyJxXi46 u46c9SSDYapc+Wo3qJU7Z/jiHPAAA7HoTxvy1t90EHPpMJyVdVqX5L75TRlzYR1tpA Eo7jvRVxwgjFM3HosB4BuCipVrworQcOq3U+ErRvDk3sk0MUhNNMXwGdLWFID6+k+Z zpOiBfZ1UPuixr+RbY92TphLQ6zhhgm2CQnuAqHYMPazaPSfXR0GGh0v0L5rXobZCx Y3H+THKFDCN+g== Date: Wed, 2 Oct 2024 11:41:28 +0200 From: Alejandro Colomar To: gcc-patches@gcc.gnu.org Cc: Alejandro Colomar , Gabriel Ravier , Jakub Jelinek , Kees Cook , Qing Zhao , Jens Gustedt , David Brown , Florian Weimer , Andreas Schwab , Timm Baeder , Daniel Plakosh , "A. Jiang" , Eugene Zelenko , Aaron Ballman , Paul Koning , Daniel Lundin , Nikolaos Strimpas , JeanHeyd Meneide , Fernando Borretti , Jonathan Protzenko , Chris Bazley , Ville Voutilainen , Alex Celeste , Jakub =?utf-8?q?=C5=81ukasiewicz?= , Douglas McIlroy , Jason Merrill , Xavier Del Campo Romero , Siddhesh Poyarekar , DJ Delorie , Carlos O'Donell , Stephen Coady , Robert Seacord , Martin Uecker , Joseph Myers , Richard Biener Subject: [PATCH v13 2/4] gcc/: Rename array_type_nelts() => array_type_nelts_minus_one() Message-ID: X-Mailer: git-send-email 2.45.2 References: <20240728141547.302478-1-alx@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLACK autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org The old name was misleading. While at it, also rename some temporary variables that are used with this function, for consistency. Link: 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() Cc: Gabriel Ravier Cc: Martin Uecker Cc: Joseph Myers Cc: Xavier Del Campo Romero Cc: Jakub Jelinek Suggested-by: Richard Biener Signed-off-by: Alejandro Colomar --- gcc/c/c-decl.cc | 10 +++++----- gcc/c/c-fold.cc | 7 ++++--- gcc/config/aarch64/aarch64.cc | 2 +- gcc/config/i386/i386.cc | 2 +- gcc/cp/decl.cc | 2 +- gcc/cp/init.cc | 8 ++++---- gcc/cp/lambda.cc | 3 ++- gcc/cp/tree.cc | 2 +- gcc/expr.cc | 8 ++++---- gcc/fortran/trans-array.cc | 2 +- gcc/fortran/trans-openmp.cc | 4 ++-- gcc/rust/backend/rust-tree.cc | 2 +- gcc/tree.cc | 4 ++-- gcc/tree.h | 2 +- 14 files changed, 30 insertions(+), 28 deletions(-) diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index aa7f69d1b7b..c73d3107efb 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -5358,7 +5358,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]". */ @@ -6306,15 +6306,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); diff --git a/gcc/c/c-fold.cc b/gcc/c/c-fold.cc index 57b67c74bd8..9ea174f79c4 100644 --- a/gcc/c/c-fold.cc +++ b/gcc/c/c-fold.cc @@ -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; diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index 27e24ba70ab..21606701725 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -1084,7 +1084,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; diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 546c964d2a4..c6407843fc5 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -24393,7 +24393,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); diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 6458e96bded..98133894c48 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -6908,7 +6908,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); diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index 20373d26988..493e64691cd 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -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. */ @@ -474,7 +474,7 @@ build_value_init_noctor (tree type, tsubst_flags_t complain) vec *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. */ @@ -4519,7 +4519,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; @@ -5178,7 +5178,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); } diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc index 0770417810e..065113bc122 100644 --- a/gcc/cp/lambda.cc +++ b/gcc/cp/lambda.cc @@ -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) diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index 31ecbb1ac79..040136c70ab 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -3088,7 +3088,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); } diff --git a/gcc/expr.cc b/gcc/expr.cc index 320be8b17a1..803da754be1 100644 --- a/gcc/expr.cc +++ b/gcc/expr.cc @@ -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 diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 8c35926436d..22ac3c1a5f3 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -9640,7 +9640,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); } diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index df1bf144e23..14cd2f9fad7 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -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); } @@ -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); diff --git a/gcc/rust/backend/rust-tree.cc b/gcc/rust/backend/rust-tree.cc index cdb79095da8..8d32e5203ae 100644 --- a/gcc/rust/backend/rust-tree.cc +++ b/gcc/rust/backend/rust-tree.cc @@ -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 diff --git a/gcc/tree.cc b/gcc/tree.cc index b14cfbe7929..7439777f307 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -3698,7 +3698,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; @@ -14789,7 +14789,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; diff --git a/gcc/tree.h b/gcc/tree.h index 93aa7d22d6f..4e29544a36c 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -4921,7 +4921,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);