From: Maciej W. Rozycki Date: Wed, 22 Nov 2023 01:18:23 +0000 (+0000) Subject: RISC-V: Sanitise NEED_EQ_NE_P case with `riscv_emit_int_compare' X-Git-Tag: basepoints/gcc-15~4436 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f5aa4e210cbcb621ead82f4b56482deaa548c13;p=thirdparty%2Fgcc.git RISC-V: Sanitise NEED_EQ_NE_P case with `riscv_emit_int_compare' For the NEED_EQ_NE_P `riscv_emit_int_compare' is documented to only emit EQ or NE comparisons against zero, however it does not catch incorrect use where a non-equality comparison has been requested and falls through to the general case then. Add a safety guard to catch such a case then. Arguably the NEED_EQ_NE_P case would best be moved into a function of its own, but let's leave it for a separate cleanup. gcc/ * config/riscv/riscv.cc (riscv_emit_int_compare): Bail out if NEED_EQ_NE_P but the comparison is neither EQ nor NE. --- diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc index 60d3f617395d..453c5f17196c 100644 --- a/gcc/config/riscv/riscv.cc +++ b/gcc/config/riscv/riscv.cc @@ -3808,6 +3808,7 @@ riscv_emit_int_compare (enum rtx_code *code, rtx *op0, rtx *op1, *op1 = const0_rtx; return; } + gcc_unreachable (); } if (splittable_const_int_operand (*op1, VOIDmode))