This patch adds a change to handle VLA's poly indices.

gcc/ChangeLog:

        * cp/decl.cc (reshape_init_array_1): Handle poly indices.

gcc/testsuite/ChangeLog:

        * g++.dg/ext/sve-sizeless-1.C: Update test to test initialize error.
        * g++.dg/ext/sve-sizeless-2.C: Likewise.
---
 gcc/cp/decl.cc                            | 11 ++++++++---
 gcc/testsuite/g++.dg/ext/sve-sizeless-1.C |  1 +
 gcc/testsuite/g++.dg/ext/sve-sizeless-2.C |  1 +
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 0e4533c6fab..1b6bbadbe9d 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -6897,15 +6897,20 @@ reshape_init_array_1 (tree elt_type, tree max_index, 
reshape_iter *d,
 
   if (sized_array_p)
     {
+      poly_uint64 midx;
       /* Minus 1 is used for zero sized arrays.  */
       if (integer_all_onesp (max_index))
        return new_init;
 
-      if (tree_fits_uhwi_p (max_index))
-       max_index_cst = tree_to_uhwi (max_index);
+      if (tree_fits_poly_uint64_p (max_index))
+       midx = tree_to_poly_uint64 (max_index);
       /* sizetype is sign extended, not zero extended.  */
       else
-       max_index_cst = tree_to_uhwi (fold_convert (size_type_node, max_index));
+       midx = tree_to_poly_uint64 (fold_convert (size_type_node, max_index));
+
+      /* For VLA vectors, we restict the number of elements in the constructor
+        to lower bound of the VLA elements.  */
+      max_index_cst = constant_lower_bound (midx);
     }
 
   /* Loop until there are no more initializers.  */
diff --git a/gcc/testsuite/g++.dg/ext/sve-sizeless-1.C 
b/gcc/testsuite/g++.dg/ext/sve-sizeless-1.C
index adee37a0551..71e320c12e4 100644
--- a/gcc/testsuite/g++.dg/ext/sve-sizeless-1.C
+++ b/gcc/testsuite/g++.dg/ext/sve-sizeless-1.C
@@ -161,6 +161,7 @@ statements (int n)
   svint8_t init_sve_sc5 = {};
   svint8_t init_sve_sc6 = { sve_sc1 };
   svint8_t init_sve_sc7 = { sve_sh1 }; // { dg-error {cannot convert 
'svint16_t' to 'svint8_t'} }
+  svint32_t init_sve_vc1 = { 0, 1, 2, 3, 4, 5 }; // { dg-error {too many 
initializers for 'svint32_t'} }
 
   // Constructor calls.
 
diff --git a/gcc/testsuite/g++.dg/ext/sve-sizeless-2.C 
b/gcc/testsuite/g++.dg/ext/sve-sizeless-2.C
index 0b86d9e8217..1228bde85bc 100644
--- a/gcc/testsuite/g++.dg/ext/sve-sizeless-2.C
+++ b/gcc/testsuite/g++.dg/ext/sve-sizeless-2.C
@@ -161,6 +161,7 @@ statements (int n)
   svint8_t init_sve_sc5 = {};
   svint8_t init_sve_sc6 = { sve_sc1 };
   svint8_t init_sve_sc7 = { sve_sh1 }; // { dg-error {cannot convert 
'svint16_t' to 'svint8_t'} }
+  svint32_t init_sve_vc1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; // { dg-error {too 
many initializers for 'svint32_t'} }
 
   // Constructor calls.
 
-- 
2.25.1

Reply via email to