mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-06 06:55:07 +00:00
Check whether related table has funcref elem in opcode call_indirect (#3999)
* check whether table has funcref elem in call_indirect * check whether table has funcref elem in call_indirect when gc is enabled
This commit is contained in:
parent
9989b1cc1b
commit
a653746b7b
|
@ -12103,6 +12103,10 @@ re_scan:
|
|||
{
|
||||
int32 idx;
|
||||
WASMFuncType *func_type;
|
||||
uint32 tbl_elem_type;
|
||||
#if WASM_ENABLE_GC != 0
|
||||
WASMRefType *elem_ref_type = NULL;
|
||||
#endif
|
||||
|
||||
read_leb_uint32(p, p_end, type_idx);
|
||||
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
|
||||
|
@ -12125,6 +12129,43 @@ re_scan:
|
|||
error_buf_size)) {
|
||||
goto fail;
|
||||
}
|
||||
tbl_elem_type =
|
||||
table_idx < module->import_table_count
|
||||
? module->import_tables[table_idx]
|
||||
.u.table.table_type.elem_type
|
||||
: module->tables[table_idx - module->import_table_count]
|
||||
.table_type.elem_type;
|
||||
|
||||
#if WASM_ENABLE_GC == 0 && WASM_ENABLE_REF_TYPES != 0
|
||||
if (tbl_elem_type != VALUE_TYPE_FUNCREF) {
|
||||
set_error_buf_v(error_buf, error_buf_size,
|
||||
"type mismatch: instruction requires table "
|
||||
"of functions but table %u has externref",
|
||||
table_idx);
|
||||
goto fail;
|
||||
}
|
||||
#elif WASM_ENABLE_GC != 0
|
||||
/* Table element must match type ref null func */
|
||||
elem_ref_type =
|
||||
table_idx < module->import_table_count
|
||||
? module->import_tables[table_idx]
|
||||
.u.table.table_type.elem_ref_type
|
||||
: module->tables[table_idx - module->import_table_count]
|
||||
.table_type.elem_ref_type;
|
||||
|
||||
if (!wasm_reftype_is_subtype_of(
|
||||
tbl_elem_type, elem_ref_type, REF_TYPE_FUNCREF, NULL,
|
||||
module->types, module->type_count)) {
|
||||
set_error_buf_v(error_buf, error_buf_size,
|
||||
"type mismatch: instruction requires "
|
||||
"reference type t match type ref null func"
|
||||
"in table %u",
|
||||
table_idx);
|
||||
goto fail;
|
||||
}
|
||||
#else
|
||||
(void)tbl_elem_type;
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
/* we need to emit before arguments */
|
||||
|
|
|
@ -6700,6 +6700,15 @@ re_scan:
|
|||
goto fail;
|
||||
}
|
||||
|
||||
bh_assert(
|
||||
(table_idx < module->import_table_count
|
||||
? module->import_tables[table_idx]
|
||||
.u.table.table_type.elem_type
|
||||
: module
|
||||
->tables[table_idx - module->import_table_count]
|
||||
.table_type.elem_type)
|
||||
== VALUE_TYPE_FUNCREF);
|
||||
|
||||
#if WASM_ENABLE_FAST_INTERP != 0
|
||||
/* we need to emit before arguments */
|
||||
emit_uint32(loader_ctx, type_idx);
|
||||
|
|
Loading…
Reference in New Issue
Block a user