Skip to content

Commit 04abbbc

Browse files
authored
gc: complete common heap type coverage in wasm_is_refheaptype_common() (#4801)
Signed-off-by: zhenweijin <zhenwei.jin@intel.com>
1 parent fcd3722 commit 04abbbc

File tree

3 files changed

+28
-13
lines changed

3 files changed

+28
-13
lines changed

core/iwasm/common/gc/gc_common.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,15 @@ wasm_ref_type_set_heap_type(wasm_ref_type_t *ref_type, bool nullable,
352352
{
353353
bool ret;
354354

355-
bh_assert(heap_type <= HEAP_TYPE_FUNC && heap_type >= HEAP_TYPE_NONE);
355+
bh_assert((heap_type >= HEAP_TYPE_ARRAY && heap_type <= HEAP_TYPE_NOFUNC)
356+
#if WASM_ENABLE_STRINGREF != 0
357+
|| heap_type == HEAP_TYPE_STRINGREF
358+
|| heap_type == HEAP_TYPE_STRINGVIEWWTF8
359+
|| heap_type == HEAP_TYPE_STRINGVIEWWTF16
360+
|| heap_type == HEAP_TYPE_STRINGVIEWITER
361+
#endif
362+
);
363+
356364
ref_type->value_type =
357365
nullable ? VALUE_TYPE_HT_NULLABLE_REF : VALUE_TYPE_HT_NON_NULLABLE_REF;
358366
ref_type->nullable = nullable;

core/iwasm/common/gc/gc_type.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,18 +269,20 @@ wasm_is_refheaptype_typeidx(const RefHeapType_Common *ref_heap_type)
269269
return ref_heap_type->heap_type >= 0 ? true : false;
270270
}
271271

272-
/* Whether a ref heap type is a common type: func/any/eq/i31/data,
273-
not (type i) or (rtt n i) or (rtt i) */
272+
/* Whether a ref heap type is a common type:
273+
func/any/eq/i31/data/nofunc/noextern, not (type i) or (rtt n i) or (rtt i) */
274274
inline static bool
275275
wasm_is_refheaptype_common(const RefHeapType_Common *ref_heap_type)
276276
{
277277
return ((ref_heap_type->heap_type >= (int32)HEAP_TYPE_ARRAY
278-
&& ref_heap_type->heap_type <= (int32)HEAP_TYPE_NONE)
278+
&& ref_heap_type->heap_type <= (int32)HEAP_TYPE_NOFUNC)
279279
#if WASM_ENABLE_STRINGREF != 0
280-
|| (ref_heap_type->heap_type >= (int32)HEAP_TYPE_STRINGVIEWITER
281-
&& ref_heap_type->heap_type <= (int32)HEAP_TYPE_I31)
280+
|| ref_heap_type->heap_type == (int32)HEAP_TYPE_STRINGREF
281+
|| ref_heap_type->heap_type == (int32)HEAP_TYPE_STRINGVIEWWTF8
282+
|| ref_heap_type->heap_type == (int32)HEAP_TYPE_STRINGVIEWWTF16
283+
|| ref_heap_type->heap_type == (int32)HEAP_TYPE_STRINGVIEWITER
282284
#endif
283-
)
285+
)
284286
? true
285287
: false;
286288
}

core/iwasm/include/gc_export.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,21 @@ typedef enum wasm_value_type_enum {
5151
typedef int32_t wasm_heap_type_t;
5252

5353
typedef enum wasm_heap_type_enum {
54+
HEAP_TYPE_NOFUNC = -0x0D,
55+
HEAP_TYPE_NOEXTERN = -0x0E,
56+
HEAP_TYPE_NONE = -0x0F,
5457
HEAP_TYPE_FUNC = -0x10,
5558
HEAP_TYPE_EXTERN = -0x11,
5659
HEAP_TYPE_ANY = -0x12,
5760
HEAP_TYPE_EQ = -0x13,
58-
HEAP_TYPE_I31 = -0x16,
59-
HEAP_TYPE_NOFUNC = -0x17,
60-
HEAP_TYPE_NOEXTERN = -0x18,
61-
HEAP_TYPE_STRUCT = -0x19,
62-
HEAP_TYPE_ARRAY = -0x1A,
63-
HEAP_TYPE_NONE = -0x1B
61+
HEAP_TYPE_I31 = -0x14,
62+
HEAP_TYPE_STRUCT = -0x15,
63+
HEAP_TYPE_ARRAY = -0x16,
64+
/* Stringref Types */
65+
HEAP_TYPE_STRINGREF = -0x19,
66+
HEAP_TYPE_STRINGVIEWWTF8 = -0x1A,
67+
HEAP_TYPE_STRINGVIEWWTF16 = -0x1E,
68+
HEAP_TYPE_STRINGVIEWITER = -0x1F
6469
} wasm_heap_type_enum;
6570

6671
struct WASMObject;

0 commit comments

Comments
 (0)