diff mbox series

[v16b,2/4] gcc/: Rename array_type_nelts => array_type_nelts_minus_one

Message ID 7418a11fcd62a75b9f144a0a1f2ba0f460069cd5.1729080460.git.alx@kernel.org
State New
Headers show
Series c: Add __countof__ operator | expand

Commit Message

Alejandro Colomar Oct. 16, 2024, 12:10 p.m. UTC
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/9fffd80-dca-2c7e-14b-6c9b509a7215@redhat.com/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

Cc: Gabriel Ravier <gabravier@gmail.com>
Cc: Martin Uecker <uecker@tugraz.at>
Cc: Joseph Myers <josmyers@redhat.com>
Cc: Xavier Del Campo Romero <xavi.dcr@tutanota.com>
Cc: Jakub Jelinek <jakub@redhat.com>
Suggested-by: Richard Biener <richard.guenther@gmail.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
---
 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(-)

Comments

Joseph Myers Oct. 16, 2024, 5:21 p.m. UTC | #1
On Wed, 16 Oct 2024, Alejandro Colomar wrote:

> The old name was misleading.
> 
> While at it, also rename some temporary variables that are used with
> this function, for consistency.

This patch is OK and should be committed (assuming it has passed bootstrap 
and regression testing).
Alejandro Colomar Oct. 16, 2024, 6:02 p.m. UTC | #2
Hi Joseph,

On Wed, Oct 16, 2024 at 05:21:39PM GMT, Joseph Myers wrote:
> On Wed, 16 Oct 2024, Alejandro Colomar wrote:
> 
> > The old name was misleading.
> > 
> > While at it, also rename some temporary variables that are used with
> > this function, for consistency.
> 
> This patch is OK and should be committed (assuming it has passed bootstrap 
> and regression testing).

Thanks!

I did bootstrap + regression testing in v15.  In v16 I got lazy and
since the changes were small, I only checked that the new tests all
pass.

Since it looks like it's close to merging, I'll run bootstrap +
regression testing again.

Have a lovely night!
Alex
Alejandro Colomar Oct. 18, 2024, 8:25 a.m. UTC | #3
Hi Joseph,

On Wed, Oct 16, 2024 at 08:02:05PM GMT, Alejandro Colomar wrote:
> Hi Joseph,
> 
> On Wed, Oct 16, 2024 at 05:21:39PM GMT, Joseph Myers wrote:
> > On Wed, 16 Oct 2024, Alejandro Colomar wrote:
> > 
> > > The old name was misleading.
> > > 
> > > While at it, also rename some temporary variables that are used with
> > > this function, for consistency.
> > 
> > This patch is OK and should be committed (assuming it has passed bootstrap 
> > and regression testing).
> 
> Thanks!
> 
> I did bootstrap + regression testing in v15.  In v16 I got lazy and
> since the changes were small, I only checked that the new tests all
> pass.
> 
> Since it looks like it's close to merging, I'll run bootstrap +
> regression testing again.

I've finished with regression testing.  It's all good for the entire
patch set.  See below.

Have a lovely day!
Alex


$ find | grep sum$ | while read f; do diff -u ../len16b_b4/$f $f; done
--- ../len16b_b4/./gcc/testsuite/gcc/gcc.sum	2024-10-16 22:35:00.073117065 +0200
+++ ./gcc/testsuite/gcc/gcc.sum	2024-10-18 01:03:29.717522166 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Wed Oct 16 20:49:15 2024
+Test run by alx on Thu Oct 17 23:17:38 2024
 Native configuration is x86_64-pc-linux-gnu
 
 		=== gcc tests ===
@@ -77826,6 +77826,29 @@
 PASS: gcc.dg/conv-2.c (test for excess errors)
 PASS: gcc.dg/conv-3.c (test for excess errors)
 PASS: gcc.dg/conv-3.c execution test
+PASS: gcc.dg/countof-compile.c  (test for errors, line 20)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 24)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 35)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 50)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 53)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 56)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 68)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 69)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 70)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 71)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 72)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 73)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 74)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 75)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 76)
+PASS: gcc.dg/countof-compile.c  (test for warnings, line 80)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 100)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 109)
+PASS: gcc.dg/countof-compile.c  (test for errors, line 114)
+PASS: gcc.dg/countof-compile.c (test for excess errors)
+PASS: gcc.dg/countof-vla.c (test for excess errors)
+PASS: gcc.dg/countof.c (test for excess errors)
+PASS: gcc.dg/countof.c execution test
 PASS: gcc.dg/cr-decimal-dig-1.c (test for excess errors)
 PASS: gcc.dg/cr-decimal-dig-2.c (test for excess errors)
 PASS: gcc.dg/cr-decimal-dig-3.c (test for excess errors)
@@ -208273,7 +208296,7 @@
 
 		=== gcc Summary ===
 
-# of expected passes		203197
+# of expected passes		203220
 # of unexpected failures	47
 # of unexpected successes	2
 # of expected failures		1467
--- ../len16b_b4/./gcc/testsuite/gfortran/gfortran.sum	2024-10-17 00:13:36.027361156 +0200
+++ ./gcc/testsuite/gfortran/gfortran.sum	2024-10-18 02:42:26.303591286 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Wed Oct 16 23:38:34 2024
+Test run by alx on Fri Oct 18 02:07:15 2024
 Native configuration is x86_64-pc-linux-gnu
 
 		=== gfortran tests ===
--- ../len16b_b4/./gcc/testsuite/objc/objc.sum	2024-10-17 00:14:42.583978154 +0200
+++ ./gcc/testsuite/objc/objc.sum	2024-10-18 02:43:33.504187051 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Thu Oct 17 00:13:36 2024
+Test run by alx on Fri Oct 18 02:42:26 2024
 Native configuration is x86_64-pc-linux-gnu
 
 		=== objc tests ===
--- ../len16b_b4/./gcc/testsuite/g++/g++.sum	2024-10-16 23:38:33.908171142 +0200
+++ ./gcc/testsuite/g++/g++.sum	2024-10-18 02:07:14.745543661 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Wed Oct 16 22:35:00 2024
+Test run by alx on Fri Oct 18 01:03:30 2024
 Native configuration is x86_64-pc-linux-gnu
 
 		=== g++ tests ===
--- ../len16b_b4/./x86_64-pc-linux-gnu/libitm/testsuite/libitm.sum	2024-10-17 03:41:54.781371501 +0200
+++ ./x86_64-pc-linux-gnu/libitm/testsuite/libitm.sum	2024-10-18 06:08:27.040788653 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Thu Oct 17 03:41:52 2024
+Test run by alx on Fri Oct 18 06:08:24 2024
 Native configuration is x86_64-pc-linux-gnu
 
 		=== libitm tests ===
--- ../len16b_b4/./x86_64-pc-linux-gnu/libgomp/testsuite/libgomp.sum	2024-10-17 03:41:52.169347276 +0200
+++ ./x86_64-pc-linux-gnu/libgomp/testsuite/libgomp.sum	2024-10-18 06:08:24.288765717 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Thu Oct 17 03:27:33 2024
+Test run by alx on Fri Oct 18 05:54:08 2024
 Native configuration is x86_64-pc-linux-gnu
 
 		=== libgomp tests ===
--- ../len16b_b4/./x86_64-pc-linux-gnu/libatomic/testsuite/libatomic.sum	2024-10-17 03:41:56.989391978 +0200
+++ ./x86_64-pc-linux-gnu/libatomic/testsuite/libatomic.sum	2024-10-18 06:08:29.288807393 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Thu Oct 17 03:41:55 2024
+Test run by alx on Fri Oct 18 06:08:27 2024
 Native configuration is x86_64-pc-linux-gnu
 
 		=== libatomic tests ===
--- ../len16b_b4/./x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum	2024-10-17 03:27:10.237000409 +0200
+++ ./x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum	2024-10-18 05:53:44.801155283 +0200
@@ -1,4 +1,4 @@
-Test run by alx on Thu Oct 17 00:15:11 2024
+Test run by alx on Fri Oct 18 02:43:39 2024
 Native configuration is x86_64-pc-linux-gnu
 
 		=== libstdc++ tests ===


> 
> Have a lovely night!
> Alex
> 
> -- 
> <https://www.alejandro-colomar.es/>
Alejandro Colomar Oct. 18, 2024, 11:22 a.m. UTC | #4
On Fri, Oct 18, 2024 at 10:25:59AM GMT, Alejandro Colomar wrote:
> Hi Joseph,
> 
> On Wed, Oct 16, 2024 at 08:02:05PM GMT, Alejandro Colomar wrote:
> > Hi Joseph,
> > 
> > On Wed, Oct 16, 2024 at 05:21:39PM GMT, Joseph Myers wrote:
> > > On Wed, 16 Oct 2024, Alejandro Colomar wrote:
> > > 
> > > > The old name was misleading.
> > > > 
> > > > While at it, also rename some temporary variables that are used with
> > > > this function, for consistency.
> > > 
> > > This patch is OK and should be committed (assuming it has passed bootstrap 
> > > and regression testing).

This patch (2/4) needs patch 1/4 for the commit message.  Otherwise
`git gcc-verify` reports a problem (Cc: tags).  Please revise patch 1/4
too.

Cheers,
Alex

> > 
> > Thanks!
> > 
> > I did bootstrap + regression testing in v15.  In v16 I got lazy and
> > since the changes were small, I only checked that the new tests all
> > pass.
> > 
> > Since it looks like it's close to merging, I'll run bootstrap +
> > regression testing again.
> 
> I've finished with regression testing.  It's all good for the entire
> patch set.  See below.
> 
> Have a lovely day!
> Alex
> 
> 
> $ find | grep sum$ | while read f; do diff -u ../len16b_b4/$f $f; done
> --- ../len16b_b4/./gcc/testsuite/gcc/gcc.sum	2024-10-16 22:35:00.073117065 +0200
> +++ ./gcc/testsuite/gcc/gcc.sum	2024-10-18 01:03:29.717522166 +0200
> @@ -1,4 +1,4 @@
> -Test run by alx on Wed Oct 16 20:49:15 2024
> +Test run by alx on Thu Oct 17 23:17:38 2024
>  Native configuration is x86_64-pc-linux-gnu
>  
>  		=== gcc tests ===
> @@ -77826,6 +77826,29 @@
>  PASS: gcc.dg/conv-2.c (test for excess errors)
>  PASS: gcc.dg/conv-3.c (test for excess errors)
>  PASS: gcc.dg/conv-3.c execution test
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 20)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 24)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 35)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 50)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 53)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 56)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 68)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 69)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 70)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 71)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 72)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 73)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 74)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 75)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 76)
> +PASS: gcc.dg/countof-compile.c  (test for warnings, line 80)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 100)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 109)
> +PASS: gcc.dg/countof-compile.c  (test for errors, line 114)
> +PASS: gcc.dg/countof-compile.c (test for excess errors)
> +PASS: gcc.dg/countof-vla.c (test for excess errors)
> +PASS: gcc.dg/countof.c (test for excess errors)
> +PASS: gcc.dg/countof.c execution test
>  PASS: gcc.dg/cr-decimal-dig-1.c (test for excess errors)
>  PASS: gcc.dg/cr-decimal-dig-2.c (test for excess errors)
>  PASS: gcc.dg/cr-decimal-dig-3.c (test for excess errors)
> @@ -208273,7 +208296,7 @@
>  
>  		=== gcc Summary ===
>  
> -# of expected passes		203197
> +# of expected passes		203220
>  # of unexpected failures	47
>  # of unexpected successes	2
>  # of expected failures		1467
> --- ../len16b_b4/./gcc/testsuite/gfortran/gfortran.sum	2024-10-17 00:13:36.027361156 +0200
> +++ ./gcc/testsuite/gfortran/gfortran.sum	2024-10-18 02:42:26.303591286 +0200
> @@ -1,4 +1,4 @@
> -Test run by alx on Wed Oct 16 23:38:34 2024
> +Test run by alx on Fri Oct 18 02:07:15 2024
>  Native configuration is x86_64-pc-linux-gnu
>  
>  		=== gfortran tests ===
> --- ../len16b_b4/./gcc/testsuite/objc/objc.sum	2024-10-17 00:14:42.583978154 +0200
> +++ ./gcc/testsuite/objc/objc.sum	2024-10-18 02:43:33.504187051 +0200
> @@ -1,4 +1,4 @@
> -Test run by alx on Thu Oct 17 00:13:36 2024
> +Test run by alx on Fri Oct 18 02:42:26 2024
>  Native configuration is x86_64-pc-linux-gnu
>  
>  		=== objc tests ===
> --- ../len16b_b4/./gcc/testsuite/g++/g++.sum	2024-10-16 23:38:33.908171142 +0200
> +++ ./gcc/testsuite/g++/g++.sum	2024-10-18 02:07:14.745543661 +0200
> @@ -1,4 +1,4 @@
> -Test run by alx on Wed Oct 16 22:35:00 2024
> +Test run by alx on Fri Oct 18 01:03:30 2024
>  Native configuration is x86_64-pc-linux-gnu
>  
>  		=== g++ tests ===
> --- ../len16b_b4/./x86_64-pc-linux-gnu/libitm/testsuite/libitm.sum	2024-10-17 03:41:54.781371501 +0200
> +++ ./x86_64-pc-linux-gnu/libitm/testsuite/libitm.sum	2024-10-18 06:08:27.040788653 +0200
> @@ -1,4 +1,4 @@
> -Test run by alx on Thu Oct 17 03:41:52 2024
> +Test run by alx on Fri Oct 18 06:08:24 2024
>  Native configuration is x86_64-pc-linux-gnu
>  
>  		=== libitm tests ===
> --- ../len16b_b4/./x86_64-pc-linux-gnu/libgomp/testsuite/libgomp.sum	2024-10-17 03:41:52.169347276 +0200
> +++ ./x86_64-pc-linux-gnu/libgomp/testsuite/libgomp.sum	2024-10-18 06:08:24.288765717 +0200
> @@ -1,4 +1,4 @@
> -Test run by alx on Thu Oct 17 03:27:33 2024
> +Test run by alx on Fri Oct 18 05:54:08 2024
>  Native configuration is x86_64-pc-linux-gnu
>  
>  		=== libgomp tests ===
> --- ../len16b_b4/./x86_64-pc-linux-gnu/libatomic/testsuite/libatomic.sum	2024-10-17 03:41:56.989391978 +0200
> +++ ./x86_64-pc-linux-gnu/libatomic/testsuite/libatomic.sum	2024-10-18 06:08:29.288807393 +0200
> @@ -1,4 +1,4 @@
> -Test run by alx on Thu Oct 17 03:41:55 2024
> +Test run by alx on Fri Oct 18 06:08:27 2024
>  Native configuration is x86_64-pc-linux-gnu
>  
>  		=== libatomic tests ===
> --- ../len16b_b4/./x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum	2024-10-17 03:27:10.237000409 +0200
> +++ ./x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum	2024-10-18 05:53:44.801155283 +0200
> @@ -1,4 +1,4 @@
> -Test run by alx on Thu Oct 17 00:15:11 2024
> +Test run by alx on Fri Oct 18 02:43:39 2024
>  Native configuration is x86_64-pc-linux-gnu
>  
>  		=== libstdc++ tests ===
> 
> 
> > 
> > Have a lovely night!
> > Alex
> > 
> > -- 
> > <https://www.alejandro-colomar.es/>
> 
> 
> 
> -- 
> <https://www.alejandro-colomar.es/>
diff mbox series

Patch

diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index 888966cb710..c91edaa8975 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -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]".  */
@@ -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);
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 5770491b30c..c3bd6f3339d 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -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;
 
diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index a1f0ae7a7e1..5d5022bf1c5 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -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);
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 0c5b5c06a12..7281818be8f 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -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);
diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index f785015e477..10b83efa850 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<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.  */
@@ -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;
@@ -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);
     }
 
diff --git a/gcc/cp/lambda.cc b/gcc/cp/lambda.cc
index e17c00217b2..d51b513f0fa 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 0a7a56cc6e2..3cac8ac4df1 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -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);
 }
 
diff --git a/gcc/expr.cc b/gcc/expr.cc
index ed64ccea766..5397c6fa380 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 0b8ef0b5e01..160a543bda2 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -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);
 	}
 
diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc
index d3783f56a69..f4c93148400 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 392c3dc879e..94c6d086bd7 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -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;
 
@@ -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;
diff --git a/gcc/tree.h b/gcc/tree.h
index d324a3f42a6..c996821c953 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -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);