https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112733
--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Created attachment 56707 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56707&action=edit gcc14-pr112733-2.patch Second patch to be tested. Turned out it is more complicated than that. If n > m, i.e. when divisor in absolute value is larger than dividend, we want divmod_internal_2 to know that, such that e.g. it skips the main loop and looks at correct most significant half limb of the divisor, but the if (s) for (i = 0; i < n; i++) b_remainder[i] = (b_dividend[i] >> s) | (b_dividend[i+1] << (HOST_BITS_PER_HALF_WIDE_INT - s)); else for (i = 0; i < n; i++) b_remainder[i] = b_dividend[i]; loops in such case already may invoke UB, because they copy stuff from b_dividend which just isn't there, at best some random upper bits, at worst crash. We can't copy more than there is in the array and need to tell the caller how much we've initialized, so that wi_pack can take it into account. While looking into this, I've noticed that I've allocated in case of XALLOCAVEC multiplication and division/remainder calculations twice or 4 times as much as really needed, so this patch fixes that too.