Skip to content

Commit

Permalink
wasm2c: Reset the segment register after call_indirect as the registe…
Browse files Browse the repository at this point in the history
…r may have changed
  • Loading branch information
shravanrn committed Oct 18, 2024
1 parent 3bcb05b commit d6e97af
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/c-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3558,6 +3558,9 @@ void CWriter::Write(const ExprList& exprs) {
Write(", ", StackVar(num_params - i));
}
Write(");", Newline());
if (IsSingleUnsharedMemory()) {
InstallSegueBase(module_->memories[0], false /* save_old_value */);
}
DropTypes(num_params + 1);
PushTypes(decl.sig.result_types);
if (num_results > 1) {
Expand Down
3 changes: 3 additions & 0 deletions test/wasm2c/check-imports.txt
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@ u32 w2c_test_f0(w2c_test* instance, u32 var_p0) {
u32 var_i0;
var_i0 = var_p0;
var_i0 = CALL_INDIRECT((*instance->w2c_env_0x5F_indirect_function_table), u32 (*)(void*), w2c_test_t1, var_i0, (*instance->w2c_env_0x5F_indirect_function_table).data[var_i0].module_instance);
#if WASM_RT_USE_SEGUE_FOR_THIS_MODULE
wasm_rt_segue_write_base((*instance->w2c_env_0x5F_linear_memory).data);
#endif
FUNC_EPILOGUE;
return var_i0;
}
Expand Down
3 changes: 3 additions & 0 deletions test/wasm2c/hello.txt
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,9 @@ void w2c_test_0x5Fstart_0(w2c_test* instance) {
var_i3 = 0u;
var_i4 = 0u;
var_i0 = CALL_INDIRECT(instance->w2c_T0, u32 (*)(void*, u32, u32, u32, u32), w2c_test_t0, var_i4, instance->w2c_T0.data[var_i4].module_instance, var_i0, var_i1, var_i2, var_i3);
#if WASM_RT_USE_SEGUE_FOR_THIS_MODULE
wasm_rt_segue_write_base(instance->w2c_memory.data);
#endif
w2c_wasi__snapshot__preview1_proc_exit(instance->w2c_wasi__snapshot__preview1_instance, var_i0);
FUNC_EPILOGUE;
}
Expand Down

0 comments on commit d6e97af

Please sign in to comment.