Fix table idx resolving in op call_indirect/return_call_indirect (#3726)
The table index in the call_indirect/return_call_indirect opcode should be one byte 0x00 when ref-types/GC isn't enabled, and should be treated as leb u32 when ref-types/GC is enabled. And make aot compiler bail out if ref-types/GC is disabled by command line argument while ref-types instructions are used.
This commit is contained in:
@ -2281,8 +2281,15 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
|
||||
bh_assert(tidx < module->module->type_count);
|
||||
cur_type = wasm_types[tidx];
|
||||
|
||||
/* clang-format off */
|
||||
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
|
||||
read_leb_uint32(frame_ip, frame_ip_end, tbl_idx);
|
||||
#else
|
||||
frame_ip++;
|
||||
tbl_idx = 0;
|
||||
#endif
|
||||
bh_assert(tbl_idx < module->table_count);
|
||||
/* clang-format on */
|
||||
|
||||
tbl_inst = wasm_get_table_inst(module, tbl_idx);
|
||||
|
||||
|
||||
@ -7149,10 +7149,10 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
|
||||
case WASM_OP_RETURN_CALL_INDIRECT:
|
||||
#endif
|
||||
skip_leb_uint32(p, p_end); /* typeidx */
|
||||
#if WASM_ENABLE_REF_TYPES == 0 && WASM_ENABLE_GC == 0
|
||||
u8 = read_uint8(p); /* 0x00 */
|
||||
#else
|
||||
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
|
||||
skip_leb_uint32(p, p_end); /* tableidx */
|
||||
#else
|
||||
u8 = read_uint8(p); /* 0x00 */
|
||||
#endif
|
||||
break;
|
||||
|
||||
@ -12005,10 +12005,12 @@ re_scan:
|
||||
read_leb_uint32(p, p_end, type_idx);
|
||||
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
|
||||
#if WASM_ENABLE_WAMR_COMPILER != 0
|
||||
if (*p != 0x00) {
|
||||
// Any non-0x00 byte requires the ref types proposal.
|
||||
// This is different from checking the table_idx value
|
||||
// since `0x80 0x00` etc. are all valid encodings of zero.
|
||||
if (p + 1 < p_end && *p != 0x00) {
|
||||
/*
|
||||
* Any non-0x00 byte requires the ref types proposal.
|
||||
* This is different from checking the table_idx value
|
||||
* since `0x80 0x00` etc. are all valid encodings of zero.
|
||||
*/
|
||||
module->is_ref_types_used = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -3501,8 +3501,11 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
|
||||
case WASM_OP_RETURN_CALL_INDIRECT:
|
||||
#endif
|
||||
skip_leb_uint32(p, p_end); /* typeidx */
|
||||
CHECK_BUF(p, p_end, 1);
|
||||
#if WASM_ENABLE_REF_TYPES != 0
|
||||
skip_leb_uint32(p, p_end); /* tableidx */
|
||||
#else
|
||||
u8 = read_uint8(p); /* 0x00 */
|
||||
#endif
|
||||
break;
|
||||
|
||||
#if WASM_ENABLE_EXCE_HANDLING != 0
|
||||
|
||||
Reference in New Issue
Block a user