https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128451
--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Richard Biener <[email protected]>: https://gcc.gnu.org/g:d2febb9b28d48cec23045e7f7f2a55028f359539 commit r17-5968-gd2febb9b28d48cec23045e7f7f2a55028f359539 Author: Richard Biener <[email protected]> Date: Thu Nov 5 11:26:22 2026 +0100 tree-optimization/128451 - use unsigned index arithmetic when lowering VEC_PERM_EXPR When lowering a VEC_PERM_EXPR piecewise, lower_vec_perm computes the element index by masking the mask element with ELEMENTS - 1 in the mask element type. With a signed mask element type that cannot represent ELEMENTS - 1 (for example signed char with 256 elements) build_int_cst wraps the constant to -1, the masking becomes a no-op and negative mask values result in out-of-bounds ARRAY_REF accesses of the temporary vector. Likewise testing the operand selection bit on the sign-extended constant index wrongly selects the second operand for negative mask values when the number of elements is not representable in the mask element type. Fix this by performing all index computations in the unsigned variant of the mask element type. PR tree-optimization/128451 * tree-vect-generic.cc (lower_vec_perm): Use the unsigned variant of the mask element type for index computations and convert the mask elements to it. * gcc.dg/torture/pr128451.c: New test.
