Skip to content

Commit c71e291

Browse files
committed
emitinlinerv32: Fix UBsan diagnostics.
Signed-off-by: Jeff Epler <jepler@gmail.com>
1 parent 5ff47f1 commit c71e291

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

py/emitinlinerv32.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ static bool validate_argument(emit_inline_asm_t *emit, qstr opcode_qstr,
501501
return false;
502502
}
503503

504-
mp_uint_t immediate = mp_obj_get_int_truncated(object) << shift;
504+
mp_uint_t immediate = ((mp_uint_t)mp_obj_get_int_truncated(object)) << shift;
505505
if (kind & U) {
506506
if (!is_in_unsigned_mask(mask, immediate)) {
507507
goto out_of_range;
@@ -660,7 +660,7 @@ static void handle_opcode(emit_inline_asm_t *emit, qstr opcode, const opcode_t *
660660
parse_register_node(arguments[1], &rs1, opcode_data->argument2_kind & C);
661661
mp_obj_t object;
662662
mp_parse_node_get_int_maybe(arguments[2], &object);
663-
mp_uint_t immediate = mp_obj_get_int_truncated(object) << opcode_data->argument3_shift;
663+
mp_uint_t immediate = ((mp_uint_t)mp_obj_get_int_truncated(object)) << opcode_data->argument3_shift;
664664
((call_rri_t)opcode_data->emitter)(&emit->as, rd, rs1, immediate);
665665
break;
666666
}
@@ -669,7 +669,7 @@ static void handle_opcode(emit_inline_asm_t *emit, qstr opcode, const opcode_t *
669669
parse_register_node(arguments[0], &rd, opcode_data->argument1_kind & C);
670670
mp_obj_t object;
671671
mp_parse_node_get_int_maybe(arguments[1], &object);
672-
mp_uint_t immediate = mp_obj_get_int_truncated(object) << opcode_data->argument2_shift;
672+
mp_uint_t immediate = ((mp_uint_t)mp_obj_get_int_truncated(object)) << opcode_data->argument2_shift;
673673
((call_ri_t)opcode_data->emitter)(&emit->as, rd, immediate);
674674
break;
675675
}

0 commit comments

Comments
 (0)