From 2eca081142f9161adda821812f74c6669935fe0a Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Wed, 18 Oct 2023 18:33:18 -0400 Subject: [PATCH] Add type checks in gcc_jit_block_add_assignment_op --- gcc/jit/libgccjit.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gcc/jit/libgccjit.cc b/gcc/jit/libgccjit.cc index 8e974f45d1c49..577dc0701fcbd 100644 --- a/gcc/jit/libgccjit.cc +++ b/gcc/jit/libgccjit.cc @@ -272,6 +272,16 @@ struct gcc_jit_extended_asm : public gcc::jit::recording::extended_asm } \ JIT_END_STMT +#define RETURN_IF_FAIL_PRINTF3(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2) \ + JIT_BEGIN_STMT \ + if (!(TEST_EXPR)) \ + { \ + jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \ + __func__, (A0), (A1), (A2)); \ + return; \ + } \ + JIT_END_STMT + #define RETURN_IF_FAIL_PRINTF4(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3) \ JIT_BEGIN_STMT \ if (!(TEST_EXPR)) \ @@ -3076,6 +3086,16 @@ gcc_jit_block_add_assignment_op (gcc_jit_block *block, lvalue->get_type ()->get_debug_string (), rvalue->get_debug_string (), rvalue->get_type ()->get_debug_string ()); + RETURN_IF_FAIL_PRINTF3 ( + lvalue->get_type ()->is_numeric () && rvalue->get_type ()->is_numeric (), ctxt, loc, + "gcc_jit_block_add_assignment_op %s has non-numeric lvalue %s (type: %s)", + gcc::jit::binary_op_reproducer_strings[op], + lvalue->get_debug_string (), lvalue->get_type ()->get_debug_string ()); + RETURN_IF_FAIL_PRINTF3 ( + rvalue->get_type ()->is_numeric () && rvalue->get_type ()->is_numeric (), ctxt, loc, + "gcc_jit_block_add_assignment_op %s has non-numeric rvalue %s (type: %s)", + gcc::jit::binary_op_reproducer_strings[op], + rvalue->get_debug_string (), rvalue->get_type ()->get_debug_string ()); gcc::jit::recording::statement *stmt = block->add_assignment_op (loc, lvalue, op, rvalue);