Skip to content

Commit 2349df1

Browse files
authored
Fix ref.func opcode check when GC is enabled (#3181)
The current code assumes that the element type of table segment can be `funcref` only, but when GC is enabled, the type can be `(ref func)` also. Fixes #3168.
1 parent 169e164 commit 2349df1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

core/iwasm/interpreter/wasm_loader.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4532,7 +4532,7 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
45324532
"unknown element segment kind");
45334533
return false;
45344534
}
4535-
#else
4535+
#else /* else of WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 */
45364536
/*
45374537
* like: 00 41 05 0b 04 00 01 00 01
45384538
* for: (elem 0 (offset (i32.const 5)) $f1 $f2 $f1 $f2)
@@ -4548,7 +4548,7 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
45484548
if (!load_func_index_vec(&p, p_end, module, table_segment,
45494549
error_buf, error_buf_size))
45504550
return false;
4551-
#endif /* WASM_ENABLE_REF_TYPES != 0 */
4551+
#endif /* end of WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 */
45524552

45534553
#if WASM_ENABLE_WAMR_COMPILER != 0
45544554
if (table_segment->elem_type == VALUE_TYPE_EXTERNREF)
@@ -12301,7 +12301,14 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1230112301
note that it doesn't matter whether the table seg's mode
1230212302
is passive, active or declarative. */
1230312303
for (i = 0; i < module->table_seg_count; i++, table_seg++) {
12304-
if (table_seg->elem_type == VALUE_TYPE_FUNCREF) {
12304+
if (table_seg->elem_type == VALUE_TYPE_FUNCREF
12305+
#if WASM_ENABLE_GC != 0
12306+
|| (table_seg->elem_type == REF_TYPE_HT_NON_NULLABLE
12307+
&& table_seg->elem_ref_type->ref_ht_common
12308+
.heap_type
12309+
== HEAP_TYPE_FUNC)
12310+
#endif
12311+
) {
1230512312
for (j = 0; j < table_seg->value_count; j++) {
1230612313
if (table_seg->init_values[j].u.ref_index
1230712314
== func_idx) {

0 commit comments

Comments
 (0)