Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fast-interp] fix stack recovery for else branch #3100

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -7395,20 +7395,29 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if WASM_ENABLE_FAST_INTERP != 0
/* Recover top param_count values of frame_offset stack */
if (block->available_param_num) {
uint32 size;
size = sizeof(int16) * block->available_param_num;
bh_memcpy_s(loader_ctx->frame_offset, size,
block->param_frame_offsets, size);
loader_ctx->frame_offset += (size / sizeof(int16));
uint32 available_param_cell_num = 0;

/* recover dynamic offset */
/* total cell num of available parameters */
for (i = 0; i < block->available_param_num; i++) {
if (block->param_frame_offsets[i]
uint32 cell_num = wasm_value_type_cell_num(
block->block_type.u.type->types[i]);

/* recover dynamic offset */
if (block->param_frame_offsets[available_param_cell_num]
>= loader_ctx->dynamic_offset) {
loader_ctx->dynamic_offset =
block->param_frame_offsets[i] + 1;
block->param_frame_offsets
[available_param_cell_num]
+ cell_num;
}

available_param_cell_num += cell_num;
}

bh_memcpy_s(
loader_ctx->frame_offset, available_param_cell_num,
block->param_frame_offsets, available_param_cell_num);
loader_ctx->frame_offset += available_param_cell_num;
}
#endif

Expand Down
25 changes: 17 additions & 8 deletions core/iwasm/interpreter/wasm_mini_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -5808,20 +5808,29 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
#if WASM_ENABLE_FAST_INTERP != 0
/* Recover top param_count values of frame_offset stack */
if (block->available_param_num) {
uint32 size;
size = sizeof(int16) * block->available_param_num;
bh_memcpy_s(loader_ctx->frame_offset, size,
block->param_frame_offsets, size);
loader_ctx->frame_offset += (size / sizeof(int16));
uint32 available_param_cell_num = 0;

/* recover dynamic offset */
/* total cell num of available parameters */
for (i = 0; i < block->available_param_num; i++) {
if (block->param_frame_offsets[i]
uint32 cell_num = wasm_value_type_cell_num(
block->block_type.u.type->types[i]);

/* recover dynamic offset */
if (block->param_frame_offsets[available_param_cell_num]
>= loader_ctx->dynamic_offset) {
loader_ctx->dynamic_offset =
block->param_frame_offsets[i] + 1;
block->param_frame_offsets
[available_param_cell_num]
+ cell_num;
}

available_param_cell_num += cell_num;
}

bh_memcpy_s(
loader_ctx->frame_offset, available_param_cell_num,
block->param_frame_offsets, available_param_cell_num);
loader_ctx->frame_offset += available_param_cell_num;
}
#endif

Expand Down