Skip to content

Commit 2eca081

Browse files
committed
Add type checks in gcc_jit_block_add_assignment_op
1 parent 5627014 commit 2eca081

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

gcc/jit/libgccjit.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,16 @@ struct gcc_jit_extended_asm : public gcc::jit::recording::extended_asm
272272
} \
273273
JIT_END_STMT
274274

275+
#define RETURN_IF_FAIL_PRINTF3(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2) \
276+
JIT_BEGIN_STMT \
277+
if (!(TEST_EXPR)) \
278+
{ \
279+
jit_error ((CTXT), (LOC), "%s: " ERR_FMT, \
280+
__func__, (A0), (A1), (A2)); \
281+
return; \
282+
} \
283+
JIT_END_STMT
284+
275285
#define RETURN_IF_FAIL_PRINTF4(TEST_EXPR, CTXT, LOC, ERR_FMT, A0, A1, A2, A3) \
276286
JIT_BEGIN_STMT \
277287
if (!(TEST_EXPR)) \
@@ -3076,6 +3086,16 @@ gcc_jit_block_add_assignment_op (gcc_jit_block *block,
30763086
lvalue->get_type ()->get_debug_string (),
30773087
rvalue->get_debug_string (),
30783088
rvalue->get_type ()->get_debug_string ());
3089+
RETURN_IF_FAIL_PRINTF3 (
3090+
lvalue->get_type ()->is_numeric () && rvalue->get_type ()->is_numeric (), ctxt, loc,
3091+
"gcc_jit_block_add_assignment_op %s has non-numeric lvalue %s (type: %s)",
3092+
gcc::jit::binary_op_reproducer_strings[op],
3093+
lvalue->get_debug_string (), lvalue->get_type ()->get_debug_string ());
3094+
RETURN_IF_FAIL_PRINTF3 (
3095+
rvalue->get_type ()->is_numeric () && rvalue->get_type ()->is_numeric (), ctxt, loc,
3096+
"gcc_jit_block_add_assignment_op %s has non-numeric rvalue %s (type: %s)",
3097+
gcc::jit::binary_op_reproducer_strings[op],
3098+
rvalue->get_debug_string (), rvalue->get_type ()->get_debug_string ());
30793099

30803100
gcc::jit::recording::statement *stmt = block->add_assignment_op (loc, lvalue, op, rvalue);
30813101

0 commit comments

Comments
 (0)