https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113576
--- Comment #8 from Hongtao Liu <liuhongt at gcc dot gnu.org> --- maybe diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 1fd957288d4..6d321f9baef 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -8035,6 +8035,9 @@ native_encode_vector_part (const_tree expr, unsigned char *ptr, int len, unsigned int extract_elts = extract_bytes * elts_per_byte; for (unsigned int i = 0; i < extract_elts; ++i) { + /* Don't encode any bit beyond the range of the vector. */ + if (first_elt + i > count) + break;