diff --git a/shared/runtime/pyexec.c b/shared/runtime/pyexec.c index 14e5e51a49aa5..df2b60e207c94 100644 --- a/shared/runtime/pyexec.c +++ b/shared/runtime/pyexec.c @@ -91,7 +91,9 @@ static int parse_compile_execute(const void *source, mp_parse_input_kind_t input nlr_buf_t nlr; nlr.ret_val = NULL; if (nlr_push(&nlr) == 0) { - mp_obj_t module_fun = mp_const_none; + // CIRCUITPY-CHANGE: Made volatile to prevent gcc from re-ordering store of function pointer into stack frame + // after call to gc_collect. For RISC-V this was causing free of the compiled function before execution. + volatile mp_obj_t module_fun = mp_const_none; // CIRCUITPY-CHANGE #if CIRCUITPY_ATEXIT if (!(exec_flags & EXEC_FLAG_SOURCE_IS_ATEXIT)) @@ -157,6 +159,7 @@ static int parse_compile_execute(const void *source, mp_parse_input_kind_t input mp_call_function_n_kw(callback->func, callback->n_pos, callback->n_kw, callback->args); } else #endif + // CIRCUITPY-CHANGE if (module_fun != mp_const_none) { mp_call_function_0(module_fun); }