Re: [PATCH v14 19/19] vect: Guard against infinite loop in vect_create_constant_vectors
Richard Biener <[email protected]> Mon, 3 Aug 2026 15:02:44 +0200
| Newsgroups | gmane.comp.gcc.patches |
|---|---|
| Message-ID | <CAFiYyc3m17GQGoBKSfp16GkZFNubPL1kC9JSNZaCcp64OyrPgg@mail.gmail.com> |
On Thu, Jul 30, 2026 at 4:58 PM Christopher Bazley <[email protected]> wrote: > > 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); This is loop invariant in the while() loop. Do we actually have a valid cause of not asserting this when !(number_of_vectors > SLP_TREE_VEC_DEFS (op_node).length ())? I don't think so. OK with asserting this right after vec_num = voprnds.length (); You can push this separately from the rest. Thanks, Richard. > + > + 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 >