mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
py/compile: Allow NULL emitter table entries.
This commit fixes a regression introduced in
1b92bda5b8, where a new architecture was
added to mpy-cross but it had no matching native emitter exists.
The result was that the architecture emitter entry point would be
correctly calculated according to the native architecture index, but if
the emitters entry points table was not updated to match the new number
of architectures an out of bound access may be performed.
Unfortunately adding RV64IMC shifted the debug emitter index further
down the table, and that table wasn't updated to reflect the lack of an
emitter for RV64. Adding a NULL entry there would cause a NULL pointer
access as there was no need to perform any check about the emitter entry
point function's validity until now.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit is contained in:
committed by
Damien George
parent
3d9a3e89cf
commit
65f994e26a
12
py/compile.c
12
py/compile.c
@@ -103,6 +103,7 @@ static const emit_method_table_t *emit_native_table[] = {
|
||||
&emit_native_xtensa_method_table,
|
||||
&emit_native_xtensawin_method_table,
|
||||
&emit_native_rv32_method_table,
|
||||
NULL,
|
||||
&emit_native_debug_method_table,
|
||||
};
|
||||
|
||||
@@ -3571,6 +3572,13 @@ void mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool
|
||||
case MP_EMIT_OPT_NATIVE_PYTHON:
|
||||
case MP_EMIT_OPT_VIPER:
|
||||
if (emit_native == NULL) {
|
||||
// The check looks like this to work around a false
|
||||
// warning in GCC 13 (and possibly later), where it
|
||||
// assumes that the check will always fail.
|
||||
if ((uintptr_t)NATIVE_EMITTER_TABLE == (uintptr_t)NULL) {
|
||||
comp->compile_error = mp_obj_new_exception_msg(&mp_type_NotImplementedError, MP_ERROR_TEXT("cannot emit native code for this architecture"));
|
||||
goto emit_finished;
|
||||
}
|
||||
emit_native = NATIVE_EMITTER(new)(&comp->emit_common, &comp->compile_error, &comp->next_label, max_num_labels);
|
||||
}
|
||||
comp->emit_method_table = NATIVE_EMITTER_TABLE;
|
||||
@@ -3603,6 +3611,10 @@ void mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool
|
||||
}
|
||||
}
|
||||
|
||||
#if MICROPY_EMIT_NATIVE
|
||||
emit_finished:
|
||||
#endif
|
||||
|
||||
if (comp->compile_error != MP_OBJ_NULL) {
|
||||
// if there is no line number for the error then use the line
|
||||
// number for the start of this scope
|
||||
|
||||
Reference in New Issue
Block a user