[PATCH v14 19/19] vect: Guard against infinite loop in vect_create_constant_vectors

Christopher Bazley <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <[email protected]>
If we need to replicate the vectors but vec_num ends up with a
value of 0 because of alterations elsewhere in this function
then the final loop never terminates because no SLP_TREE_VEC_DEFS
are pushed by its inner loop.  This change eases debugging.

gcc/ChangeLog:

	* tree-vect-slp.cc (vect_create_constant_vectors):
	Add an assertion to guard against the outer loop never
	terminating because the inner loop is never entered.
---
 gcc/tree-vect-slp.cc | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc
index ca9bae97e7e..0880875bcf0 100644
--- a/gcc/tree-vect-slp.cc
+++ b/gcc/tree-vect-slp.cc
@@ -11282,9 +11282,15 @@ vect_create_constant_vectors (vec_info *vinfo, slp_tree op_node)
      NUMBER_OF_SCALARS/NUNITS or NUNITS/NUMBER_OF_SCALARS, and hence we have
      to replicate the vectors.  */
   while (number_of_vectors > SLP_TREE_VEC_DEFS (op_node).length ())
-    for (i = 0; SLP_TREE_VEC_DEFS (op_node).iterate (i, &vop) && i < vec_num;
-	 i++)
-      SLP_TREE_VEC_DEFS (op_node).quick_push (vop);
+    {
+      /* Guard against the outer loop never terminating because the
+	 inner loop is never entered.  */
+      gcc_checking_assert (vec_num > 0);
+
+      for (i = 0; SLP_TREE_VEC_DEFS (op_node).iterate (i, &vop) && i < vec_num;
+	   i++)
+	SLP_TREE_VEC_DEFS (op_node).quick_push (vop);
+    }
 }
 
 /* Get the scalar definition of the Nth lane from SLP_NODE or NULL_TREE
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.