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 https://github.com/bytecodealliance/wasm-micro-runtime/issues/3409.
This commit is contained in:
TianlongLiang
2024-05-13 16:42:01 +08:00
committed by GitHub
parent 22eef3d88d
commit c6d42db598
3 changed files with 34 additions and 8 deletions

View File

@ -2919,7 +2919,8 @@ load_tag_import(const uint8 **p_buf, const uint8 *buf_end,
goto fail;
}
WASMType *declare_tag_type = parent_module->types[declare_type_index];
WASMFuncType *declare_tag_type =
(WASMFuncType *)parent_module->types[declare_type_index];
/* check, that the type of the declared tag returns void */
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,
/* get return type (must be 0) */
/* check, that the type of the referred tag returns void */
WASMType *func_type = (WASMType *)module->types[tag_type];
WASMFuncType *func_type = (WASMFuncType *)module->types[tag_type];
if (func_type->result_count != 0) {
set_error_buf(error_buf, error_buf_size,
"non-empty tag result type");
@ -11122,7 +11123,7 @@ re_scan:
/* the tag_type is stored in either the WASMTag (section tags)
* or WASMTagImport (import tag) */
WASMType *tag_type = NULL;
WASMFuncType *tag_type = NULL;
if (tag_index < module->import_tag_count) {
tag_type = module->import_tags[tag_index].u.tag.tag_type;
}
@ -11145,11 +11146,36 @@ re_scan:
/* Check stack values match return types by comparing tag param
* types with stack cells */
uint8 *frame_ref = loader_ctx->frame_ref;
#if WASM_ENABLE_GC != 0
WASMRefTypeMap *frame_reftype_map =
loader_ctx->frame_reftype_map;
uint32 frame_reftype_map_num = loader_ctx->reftype_map_num;
param_reftype_maps = tag_type->ref_type_maps;
/* For tag_type function, it shouldn't have result_count = 0 */
param_reftype_map_count = tag_type->ref_type_map_count;
param_count = (int32)tag_type->param_count;
#endif
for (int tti = (int32)tag_type->param_count - 1; tti >= 0;
tti--) {
#if WASM_ENABLE_GC != 0
local_type = tag_type->types[tti];
local_idx = tti;
/* Get the wasm_ref_type if the local_type is multibyte
* type */
GET_LOCAL_REFTYPE();
#endif
if (!check_stack_top_values(
loader_ctx, frame_ref, available_stack_cell,
tag_type->types[tti], error_buf, error_buf_size)) {
#if WASM_ENABLE_GC != 0
frame_reftype_map, frame_reftype_map_num,
#endif
tag_type->types[tti],
#if WASM_ENABLE_GC != 0
&wasm_ref_type,
#endif
error_buf, error_buf_size)) {
snprintf(error_buf, error_buf_size,
"type mismatch: instruction requires [%s] but "
"stack has [%s]",
@ -11232,7 +11258,7 @@ re_scan:
/* the tag_type is stored in either the WASMTag (section tags)
* or WASMTagImport (import tag) */
WASMType *func_type = NULL;
WASMFuncType *func_type = NULL;
if (tag_index < module->import_tag_count) {
func_type = module->import_tags[tag_index].u.tag.tag_type;
}