Skip to content

Commit f297e08

Browse files
committed
revert changes, read heap_type by p_copy
1 parent 17ac8c1 commit f297e08

1 file changed

Lines changed: 23 additions & 29 deletions

File tree

core/iwasm/interpreter/wasm_loader.c

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -830,59 +830,53 @@ load_init_expr(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end,
830830
case INIT_EXPR_TYPE_REFNULL_CONST:
831831
{
832832
uint8 type1;
833-
834-
#if WASM_ENABLE_GC == 0
833+
#if WASM_ENABLE_GC != 0
834+
const uint8 *p_copy = p;
835+
int32 heap_type;
836+
read_leb_int32(p_copy, p_end, heap_type);
837+
#endif
835838
CHECK_BUF(p, p_end, 1);
836839
type1 = read_uint8(p);
837840

841+
#if WASM_ENABLE_GC == 0
838842
cur_value.ref_index = NULL_REF;
839843
if (!push_const_expr_stack(&const_expr_ctx, flag, type1,
840844
&cur_value, error_buf,
841845
error_buf_size))
842846
goto fail;
843847
#else
844-
int32 heap_type;
845-
read_leb_int32(p, p_end, heap_type);
846848
cur_value.gc_obj = NULL_REF;
847849

848850
if (heap_type >= 0) {
849851
if (!check_type_index(module, module->type_count, heap_type,
850852
error_buf, error_buf_size)) {
851853
goto fail;
852854
}
853-
wasm_set_refheaptype_typeidx(&cur_ref_type.ref_ht_typeidx,
854-
true, heap_type);
855-
type1 = cur_ref_type.ref_type;
856-
857-
/*
858-
* Since wasm_set_refheaptype_typeidx(...) always sets type1
859-
* to REF_TYPE_HT_NULLABLE, the condition (!is_byte_a_type
860-
* || wasm_is_type_multi_byte_byte()) is always true. Thus,
861-
* this validation is no longer necessary and has been
862-
* removed.
863-
*/
864-
if (!push_const_expr_stack(&const_expr_ctx, flag, type1,
865-
&cur_ref_type, 0, &cur_value,
866-
error_buf, error_buf_size))
867-
goto fail;
868855
}
869856
else {
870857
if (!wasm_is_valid_heap_type(heap_type)) {
871858
set_error_buf_v(error_buf, error_buf_size,
872859
"unknown type %d", heap_type);
873860
goto fail;
874861
}
875-
/*
876-
* When heap_type < 0, there is no need to call
877-
* check_type_index, and the condition
878-
* (!is_byte_a_type(type1) ||
879-
* wasm_is_type_multi_byte_type(type1)) is always false.
880-
* Therefore, for both reasons, check_type_index is
881-
* unnecessary here. If the implementation changes in the
882-
* future, this check may be needed.
883-
*/
884-
type1 = (uint8)((int32)0x80 + heap_type);
862+
}
885863

864+
if (!is_byte_a_type(type1)
865+
|| wasm_is_type_multi_byte_type(type1)) {
866+
p--;
867+
read_leb_uint32(p, p_end, type_idx);
868+
if (!check_type_index(module, module->type_count, type_idx,
869+
error_buf, error_buf_size))
870+
goto fail;
871+
wasm_set_refheaptype_typeidx(&cur_ref_type.ref_ht_typeidx,
872+
true, type_idx);
873+
if (!push_const_expr_stack(&const_expr_ctx, flag,
874+
cur_ref_type.ref_type,
875+
&cur_ref_type, 0, &cur_value,
876+
error_buf, error_buf_size))
877+
goto fail;
878+
}
879+
else {
886880
if (!push_const_expr_stack(&const_expr_ctx, flag, type1,
887881
NULL, 0, &cur_value, error_buf,
888882
error_buf_size))

0 commit comments

Comments
 (0)