From 04abbbcfbe4a5ef69124d8f32779761989570548 Mon Sep 17 00:00:00 2001 From: Zhenwei Jin <109658203+kylo5aby@users.noreply.github.com> Date: Wed, 28 Jan 2026 13:03:20 +0800 Subject: [PATCH] gc: complete common heap type coverage in wasm_is_refheaptype_common() (#4801) Signed-off-by: zhenweijin --- core/iwasm/common/gc/gc_common.c | 10 +++++++++- core/iwasm/common/gc/gc_type.h | 14 ++++++++------ core/iwasm/include/gc_export.h | 17 +++++++++++------ 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/core/iwasm/common/gc/gc_common.c b/core/iwasm/common/gc/gc_common.c index 5cc869a65..7c2c15433 100644 --- a/core/iwasm/common/gc/gc_common.c +++ b/core/iwasm/common/gc/gc_common.c @@ -352,7 +352,15 @@ wasm_ref_type_set_heap_type(wasm_ref_type_t *ref_type, bool nullable, { bool ret; - bh_assert(heap_type <= HEAP_TYPE_FUNC && heap_type >= HEAP_TYPE_NONE); + bh_assert((heap_type >= HEAP_TYPE_ARRAY && heap_type <= HEAP_TYPE_NOFUNC) +#if WASM_ENABLE_STRINGREF != 0 + || heap_type == HEAP_TYPE_STRINGREF + || heap_type == HEAP_TYPE_STRINGVIEWWTF8 + || heap_type == HEAP_TYPE_STRINGVIEWWTF16 + || heap_type == HEAP_TYPE_STRINGVIEWITER +#endif + ); + ref_type->value_type = nullable ? VALUE_TYPE_HT_NULLABLE_REF : VALUE_TYPE_HT_NON_NULLABLE_REF; ref_type->nullable = nullable; diff --git a/core/iwasm/common/gc/gc_type.h b/core/iwasm/common/gc/gc_type.h index 919c8e501..29b171e5a 100644 --- a/core/iwasm/common/gc/gc_type.h +++ b/core/iwasm/common/gc/gc_type.h @@ -269,18 +269,20 @@ wasm_is_refheaptype_typeidx(const RefHeapType_Common *ref_heap_type) return ref_heap_type->heap_type >= 0 ? true : false; } -/* Whether a ref heap type is a common type: func/any/eq/i31/data, - not (type i) or (rtt n i) or (rtt i) */ +/* Whether a ref heap type is a common type: + func/any/eq/i31/data/nofunc/noextern, not (type i) or (rtt n i) or (rtt i) */ inline static bool wasm_is_refheaptype_common(const RefHeapType_Common *ref_heap_type) { return ((ref_heap_type->heap_type >= (int32)HEAP_TYPE_ARRAY - && ref_heap_type->heap_type <= (int32)HEAP_TYPE_NONE) + && ref_heap_type->heap_type <= (int32)HEAP_TYPE_NOFUNC) #if WASM_ENABLE_STRINGREF != 0 - || (ref_heap_type->heap_type >= (int32)HEAP_TYPE_STRINGVIEWITER - && ref_heap_type->heap_type <= (int32)HEAP_TYPE_I31) + || ref_heap_type->heap_type == (int32)HEAP_TYPE_STRINGREF + || ref_heap_type->heap_type == (int32)HEAP_TYPE_STRINGVIEWWTF8 + || ref_heap_type->heap_type == (int32)HEAP_TYPE_STRINGVIEWWTF16 + || ref_heap_type->heap_type == (int32)HEAP_TYPE_STRINGVIEWITER #endif - ) + ) ? true : false; } diff --git a/core/iwasm/include/gc_export.h b/core/iwasm/include/gc_export.h index f7426f41d..bf2c36d60 100644 --- a/core/iwasm/include/gc_export.h +++ b/core/iwasm/include/gc_export.h @@ -51,16 +51,21 @@ typedef enum wasm_value_type_enum { typedef int32_t wasm_heap_type_t; typedef enum wasm_heap_type_enum { + HEAP_TYPE_NOFUNC = -0x0D, + HEAP_TYPE_NOEXTERN = -0x0E, + HEAP_TYPE_NONE = -0x0F, HEAP_TYPE_FUNC = -0x10, HEAP_TYPE_EXTERN = -0x11, HEAP_TYPE_ANY = -0x12, HEAP_TYPE_EQ = -0x13, - HEAP_TYPE_I31 = -0x16, - HEAP_TYPE_NOFUNC = -0x17, - HEAP_TYPE_NOEXTERN = -0x18, - HEAP_TYPE_STRUCT = -0x19, - HEAP_TYPE_ARRAY = -0x1A, - HEAP_TYPE_NONE = -0x1B + HEAP_TYPE_I31 = -0x14, + HEAP_TYPE_STRUCT = -0x15, + HEAP_TYPE_ARRAY = -0x16, + /* Stringref Types */ + HEAP_TYPE_STRINGREF = -0x19, + HEAP_TYPE_STRINGVIEWWTF8 = -0x1A, + HEAP_TYPE_STRINGVIEWWTF16 = -0x1E, + HEAP_TYPE_STRINGVIEWITER = -0x1F } wasm_heap_type_enum; struct WASMObject;