@@ -12103,6 +12103,10 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1210312103 {
1210412104 int32 idx;
1210512105 WASMFuncType *func_type;
12106+ uint32 tbl_elem_type;
12107+ #if WASM_ENABLE_GC != 0
12108+ WASMRefType *elem_ref_type = NULL;
12109+ #endif
1210612110
1210712111 read_leb_uint32(p, p_end, type_idx);
1210812112#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
@@ -12125,6 +12129,43 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1212512129 error_buf_size)) {
1212612130 goto fail;
1212712131 }
12132+ tbl_elem_type =
12133+ table_idx < module->import_table_count
12134+ ? module->import_tables[table_idx]
12135+ .u.table.table_type.elem_type
12136+ : module->tables[table_idx - module->import_table_count]
12137+ .table_type.elem_type;
12138+
12139+ #if WASM_ENABLE_GC == 0 && WASM_ENABLE_REF_TYPES != 0
12140+ if (tbl_elem_type != VALUE_TYPE_FUNCREF) {
12141+ set_error_buf_v(error_buf, error_buf_size,
12142+ "type mismatch: instruction requires table "
12143+ "of functions but table %u has externref",
12144+ table_idx);
12145+ goto fail;
12146+ }
12147+ #elif WASM_ENABLE_GC != 0
12148+ /* Table element must match type ref null func */
12149+ elem_ref_type =
12150+ table_idx < module->import_table_count
12151+ ? module->import_tables[table_idx]
12152+ .u.table.table_type.elem_ref_type
12153+ : module->tables[table_idx - module->import_table_count]
12154+ .table_type.elem_ref_type;
12155+
12156+ if (!wasm_reftype_is_subtype_of(
12157+ tbl_elem_type, elem_ref_type, REF_TYPE_FUNCREF, NULL,
12158+ module->types, module->type_count)) {
12159+ set_error_buf_v(error_buf, error_buf_size,
12160+ "type mismatch: instruction requires "
12161+ "reference type t match type ref null func"
12162+ "in table %u",
12163+ table_idx);
12164+ goto fail;
12165+ }
12166+ #else
12167+ (void)tbl_elem_type;
12168+ #endif
1212812169
1212912170#if WASM_ENABLE_FAST_INTERP != 0
1213012171 /* we need to emit before arguments */
0 commit comments