Skip to content

Commit b39f4c5

Browse files
Fix drop opcode issue in fast interpreter (#1231)
Fix fast interpreter issue reported in #1230
1 parent e0a8aa0 commit b39f4c5

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

core/iwasm/interpreter/wasm_loader.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6552,6 +6552,16 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
65526552
}
65536553

65546554
#if WASM_ENABLE_FAST_INTERP != 0
6555+
/* For the first traverse, the initial value of preserved_local_offset has
6556+
* not been determined, we use the INT16_MAX to represent that a slot has
6557+
* been copied to preserve space. For second traverse, this field will be
6558+
* set to the appropriate value in wasm_loader_ctx_reinit.
6559+
* This is for Issue #1230,
6560+
* https://github.com/bytecodealliance/wasm-micro-runtime/issues/1230, the
6561+
* drop opcodes need to know which slots are preserved, so those slots will
6562+
* not be treated as dynamically allocated slots */
6563+
loader_ctx->preserved_local_offset = INT16_MAX;
6564+
65556565
re_scan:
65566566
if (loader_ctx->code_compiled_size > 0) {
65576567
if (!wasm_loader_ctx_reinit(loader_ctx)) {
@@ -7209,8 +7219,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
72097219
#if WASM_ENABLE_FAST_INTERP != 0
72107220
skip_label();
72117221
loader_ctx->frame_offset--;
7212-
if (*(loader_ctx->frame_offset)
7213-
> loader_ctx->start_dynamic_offset)
7222+
if ((*(loader_ctx->frame_offset)
7223+
> loader_ctx->start_dynamic_offset)
7224+
&& (*(loader_ctx->frame_offset)
7225+
< loader_ctx->max_dynamic_offset))
72147226
loader_ctx->dynamic_offset--;
72157227
#endif
72167228
}
@@ -7223,8 +7235,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
72237235
#if WASM_ENABLE_FAST_INTERP != 0
72247236
skip_label();
72257237
loader_ctx->frame_offset -= 2;
7226-
if (*(loader_ctx->frame_offset)
7227-
> loader_ctx->start_dynamic_offset)
7238+
if ((*(loader_ctx->frame_offset)
7239+
> loader_ctx->start_dynamic_offset)
7240+
&& (*(loader_ctx->frame_offset)
7241+
< loader_ctx->max_dynamic_offset))
72287242
loader_ctx->dynamic_offset -= 2;
72297243
#endif
72307244
}

core/iwasm/interpreter/wasm_mini_loader.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4870,6 +4870,16 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
48704870
}
48714871

48724872
#if WASM_ENABLE_FAST_INTERP != 0
4873+
/* For the first traverse, the initial value of preserved_local_offset has
4874+
* not been determined, we use the INT16_MAX to represent that a slot has
4875+
* been copied to preserve space. For second traverse, this field will be
4876+
* set to the appropriate value in wasm_loader_ctx_reinit.
4877+
* This is for Issue #1230,
4878+
* https://github.com/bytecodealliance/wasm-micro-runtime/issues/1230, the
4879+
* drop opcodes need to know which slots are preserved, so those slots will
4880+
* not be treated as dynamically allocated slots */
4881+
loader_ctx->preserved_local_offset = INT16_MAX;
4882+
48734883
re_scan:
48744884
if (loader_ctx->code_compiled_size > 0) {
48754885
if (!wasm_loader_ctx_reinit(loader_ctx)) {
@@ -5446,8 +5456,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
54465456
#if WASM_ENABLE_FAST_INTERP != 0
54475457
skip_label();
54485458
loader_ctx->frame_offset--;
5449-
if (*(loader_ctx->frame_offset)
5450-
> loader_ctx->start_dynamic_offset)
5459+
if ((*(loader_ctx->frame_offset)
5460+
> loader_ctx->start_dynamic_offset)
5461+
&& (*(loader_ctx->frame_offset)
5462+
< loader_ctx->max_dynamic_offset))
54515463
loader_ctx->dynamic_offset--;
54525464
#endif
54535465
}
@@ -5460,9 +5472,11 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
54605472
#if WASM_ENABLE_FAST_INTERP != 0
54615473
skip_label();
54625474
loader_ctx->frame_offset -= 2;
5463-
if (*(loader_ctx->frame_offset)
5464-
> loader_ctx->start_dynamic_offset)
5465-
loader_ctx->dynamic_offset -= 2;
5475+
if ((*(loader_ctx->frame_offset)
5476+
> loader_ctx->start_dynamic_offset)
5477+
&& (*(loader_ctx->frame_offset)
5478+
< loader_ctx->max_dynamic_offset))
5479+
loader_ctx->dynamic_offset--;
54665480
#endif
54675481
}
54685482
else {

0 commit comments

Comments
 (0)