Skip to content

Commit c6d42db

Browse files
Correct Exception Handling tag type when GC is enabled (#3413)
Use `WASMFuncType` to represent tag_type in `WASMTagImport` and `WASMTag` so that the type definition is consistent no matter to GC is enabled or not. This PR fixes #3409.
1 parent 22eef3d commit c6d42db

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

core/iwasm/interpreter/wasm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ typedef struct WASMTagImport {
574574
char *field_name;
575575
uint8 attribute; /* the type of the tag (numerical) */
576576
uint32 type; /* the type of the catch function (numerical)*/
577-
WASMType *tag_type;
577+
WASMFuncType *tag_type;
578578
void *tag_ptr_linked;
579579

580580
#if WASM_ENABLE_MULTI_MODULE != 0
@@ -706,7 +706,7 @@ struct WASMFunction {
706706
struct WASMTag {
707707
uint8 attribute; /* the attribute property of the tag (expected to be 0) */
708708
uint32 type; /* the type of the tag (expected valid inden in type table) */
709-
WASMType *tag_type;
709+
WASMFuncType *tag_type;
710710
};
711711
#endif
712712

core/iwasm/interpreter/wasm_interp_classic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
16121612
/* landing pad for the rethrow ? */
16131613
find_a_catch_handler:
16141614
{
1615-
WASMType *tag_type = NULL;
1615+
WASMFuncType *tag_type = NULL;
16161616
uint32 cell_num_to_copy = 0;
16171617
if (IS_INVALID_TAGINDEX(exception_tag_index)) {
16181618
/*

core/iwasm/interpreter/wasm_loader.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2919,7 +2919,8 @@ load_tag_import(const uint8 **p_buf, const uint8 *buf_end,
29192919
goto fail;
29202920
}
29212921

2922-
WASMType *declare_tag_type = parent_module->types[declare_type_index];
2922+
WASMFuncType *declare_tag_type =
2923+
(WASMFuncType *)parent_module->types[declare_type_index];
29232924

29242925
/* check, that the type of the declared tag returns void */
29252926
if (declare_tag_type->result_count != 0) {
@@ -4806,7 +4807,7 @@ load_tag_section(const uint8 *buf, const uint8 *buf_end, const uint8 *buf_code,
48064807

48074808
/* get return type (must be 0) */
48084809
/* check, that the type of the referred tag returns void */
4809-
WASMType *func_type = (WASMType *)module->types[tag_type];
4810+
WASMFuncType *func_type = (WASMFuncType *)module->types[tag_type];
48104811
if (func_type->result_count != 0) {
48114812
set_error_buf(error_buf, error_buf_size,
48124813
"non-empty tag result type");
@@ -11122,7 +11123,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1112211123

1112311124
/* the tag_type is stored in either the WASMTag (section tags)
1112411125
* or WASMTagImport (import tag) */
11125-
WASMType *tag_type = NULL;
11126+
WASMFuncType *tag_type = NULL;
1112611127
if (tag_index < module->import_tag_count) {
1112711128
tag_type = module->import_tags[tag_index].u.tag.tag_type;
1112811129
}
@@ -11145,11 +11146,36 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1114511146
/* Check stack values match return types by comparing tag param
1114611147
* types with stack cells */
1114711148
uint8 *frame_ref = loader_ctx->frame_ref;
11149+
#if WASM_ENABLE_GC != 0
11150+
WASMRefTypeMap *frame_reftype_map =
11151+
loader_ctx->frame_reftype_map;
11152+
uint32 frame_reftype_map_num = loader_ctx->reftype_map_num;
11153+
param_reftype_maps = tag_type->ref_type_maps;
11154+
/* For tag_type function, it shouldn't have result_count = 0 */
11155+
param_reftype_map_count = tag_type->ref_type_map_count;
11156+
param_count = (int32)tag_type->param_count;
11157+
#endif
11158+
1114811159
for (int tti = (int32)tag_type->param_count - 1; tti >= 0;
1114911160
tti--) {
11161+
#if WASM_ENABLE_GC != 0
11162+
local_type = tag_type->types[tti];
11163+
local_idx = tti;
11164+
/* Get the wasm_ref_type if the local_type is multibyte
11165+
* type */
11166+
GET_LOCAL_REFTYPE();
11167+
#endif
11168+
1115011169
if (!check_stack_top_values(
1115111170
loader_ctx, frame_ref, available_stack_cell,
11152-
tag_type->types[tti], error_buf, error_buf_size)) {
11171+
#if WASM_ENABLE_GC != 0
11172+
frame_reftype_map, frame_reftype_map_num,
11173+
#endif
11174+
tag_type->types[tti],
11175+
#if WASM_ENABLE_GC != 0
11176+
&wasm_ref_type,
11177+
#endif
11178+
error_buf, error_buf_size)) {
1115311179
snprintf(error_buf, error_buf_size,
1115411180
"type mismatch: instruction requires [%s] but "
1115511181
"stack has [%s]",
@@ -11232,7 +11258,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1123211258

1123311259
/* the tag_type is stored in either the WASMTag (section tags)
1123411260
* or WASMTagImport (import tag) */
11235-
WASMType *func_type = NULL;
11261+
WASMFuncType *func_type = NULL;
1123611262
if (tag_index < module->import_tag_count) {
1123711263
func_type = module->import_tags[tag_index].u.tag.tag_type;
1123811264
}

0 commit comments

Comments
 (0)