Skip to content

Commit 0020653

Browse files
committed
Merged the if-else conditions
1 parent 038e2fc commit 0020653

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

core/iwasm/interpreter/wasm_loader.c

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ load_init_expr(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end,
843843
#else
844844
int32 heap_type;
845845
read_leb_int32(p, p_end, heap_type);
846+
cur_value.gc_obj = NULL_REF;
846847

847848
if (heap_type >= 0) {
848849
if (!check_type_index(module, module->type_count, heap_type,
@@ -852,27 +853,39 @@ load_init_expr(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end,
852853
wasm_set_refheaptype_typeidx(&cur_ref_type.ref_ht_typeidx,
853854
true, heap_type);
854855
type1 = cur_ref_type.ref_type;
856+
857+
if (!is_byte_a_type(type1)
858+
|| wasm_is_type_multi_byte_type(type1)) {
859+
if (!push_const_expr_stack(&const_expr_ctx, flag,
860+
cur_ref_type.ref_type,
861+
&cur_ref_type, 0, &cur_value,
862+
error_buf, error_buf_size))
863+
goto fail;
864+
}
865+
else {
866+
if (!push_const_expr_stack(&const_expr_ctx, flag, type1,
867+
NULL, 0, &cur_value,
868+
error_buf, error_buf_size))
869+
goto fail;
870+
}
855871
}
856872
else {
857873
if (!wasm_is_valid_heap_type(heap_type)) {
858874
set_error_buf_v(error_buf, error_buf_size,
859875
"unknown type %d", heap_type);
860876
goto fail;
861877
}
878+
/*
879+
* When heap_type < 0 and wasm_is_valid_heap_type(heap_type)
880+
* is true, under the current implementation, the condition
881+
* (!is_byte_a_type(type1) ||
882+
* wasm_is_type_multi_byte_type(type1)) will always be
883+
* false, so there is no need to check_type_index here. If
884+
* the implementation changes in the future, this check may
885+
* be needed.
886+
*/
862887
type1 = (uint8)((int32)0x80 + heap_type);
863-
}
864-
865-
cur_value.gc_obj = NULL_REF;
866888

867-
if (!is_byte_a_type(type1)
868-
|| wasm_is_type_multi_byte_type(type1)) {
869-
if (!push_const_expr_stack(&const_expr_ctx, flag,
870-
cur_ref_type.ref_type,
871-
&cur_ref_type, 0, &cur_value,
872-
error_buf, error_buf_size))
873-
goto fail;
874-
}
875-
else {
876889
if (!push_const_expr_stack(&const_expr_ctx, flag, type1,
877890
NULL, 0, &cur_value, error_buf,
878891
error_buf_size))

0 commit comments

Comments
 (0)