https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118248
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #20 from Jakub Jelinek <jakub at gcc dot gnu.org> --- So, isn't the right fix instead: --- gcc/config/riscv/riscv-string.cc.jj 2025-02-12 11:04:10.096326158 +0100 +++ gcc/config/riscv/riscv-string.cc 2025-02-12 21:19:43.039421148 +0100 @@ -804,7 +804,7 @@ static void riscv_block_move_straight (rtx dest, rtx src, unsigned HOST_WIDE_INT length, unsigned HOST_WIDE_INT align) { - unsigned HOST_WIDE_INT offset, delta; + unsigned HOST_WIDE_INT offset = 0, delta; unsigned HOST_WIDE_INT bits; int i; enum machine_mode mode; @@ -815,20 +815,25 @@ riscv_block_move_straight (rtx dest, rtx mode = mode_for_size (bits, MODE_INT, 0).require (); delta = bits / BITS_PER_UNIT; - /* Allocate a buffer for the temporary registers. */ - regs = XALLOCAVEC (rtx, length / delta - 1); - - /* Load as many BITS-sized chunks as possible. Use a normal load if - the source has enough alignment, otherwise use left/right pairs. */ - for (offset = 0, i = 0; offset + 2 * delta <= length; offset += delta, i++) + if (2 * delta <= length) { - regs[i] = gen_reg_rtx (mode); - riscv_emit_move (regs[i], adjust_address (src, mode, offset)); - } + /* Allocate a buffer for the temporary registers. */ + regs = XALLOCAVEC (rtx, length / delta - 1); - /* Copy the chunks to the destination. */ - for (offset = 0, i = 0; offset + 2 * delta <= length; offset += delta, i++) - riscv_emit_move (adjust_address (dest, mode, offset), regs[i]); + /* Load as many BITS-sized chunks as possible. Use a normal load if + the source has enough alignment, otherwise use left/right pairs. */ + for (offset = 0, i = 0; offset + 2 * delta <= length; + offset += delta, i++) + { + regs[i] = gen_reg_rtx (mode); + riscv_emit_move (regs[i], adjust_address (src, mode, offset)); + } + + /* Copy the chunks to the destination. */ + for (offset = 0, i = 0; offset + 2 * delta <= length; + offset += delta, i++) + riscv_emit_move (adjust_address (dest, mode, offset), regs[i]); + } /* Mop up any left-over bytes. */ if (offset < length) Or - regs = XALLOCAVEC (rtx, length / delta - 1); + regs = 2 * delta <= length ? XALLOCAVEC (rtx, length / delta - 1) : NULL; ?