@@ -3307,10 +3307,12 @@ wasm_loader_find_block_addr(BlockAddr *block_addr_cache,
33073307 break ;
33083308
33093309 case WASM_OP_CALL :
3310+ case WASM_OP_RETURN_CALL :
33103311 skip_leb_uint32 (p , p_end ); /* funcidx */
33113312 break ;
33123313
33133314 case WASM_OP_CALL_INDIRECT :
3315+ case WASM_OP_RETURN_CALL_INDIRECT :
33143316 skip_leb_uint32 (p , p_end ); /* typeidx */
33153317 CHECK_BUF (p , p_end , 1 );
33163318 u8 = read_uint8 (p ); /* 0x00 */
@@ -5795,7 +5797,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
57955797 {
57965798 int32 idx ;
57975799 uint8 ret_type ;
5798- for (idx = (int32 )func -> func_type -> result_count - 1 ; idx >= 0 ; idx -- ) {
5800+
5801+ for (idx = (int32 )func -> func_type -> result_count - 1 ; idx >= 0 ;
5802+ idx -- ) {
57995803 ret_type = * (func -> func_type -> types
58005804 + func -> func_type -> param_count + idx );
58015805 POP_TYPE (ret_type );
@@ -5812,6 +5816,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
58125816 }
58135817
58145818 case WASM_OP_CALL :
5819+ case WASM_OP_RETURN_CALL :
58155820 {
58165821 WASMType * func_type ;
58175822 uint32 func_idx ;
@@ -5844,22 +5849,47 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
58445849 }
58455850 }
58465851
5847- for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5848- PUSH_TYPE (func_type -> types [func_type -> param_count + i ]);
5852+ if (opcode == WASM_OP_CALL ) {
5853+ for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5854+ PUSH_TYPE (func_type -> types [func_type -> param_count + i ]);
58495855#if WASM_ENABLE_FAST_INTERP != 0
5850- /* Here we emit each return value's dynamic_offset. But in fact
5851- * these offsets are continuous, so interpreter only need to get
5852- * the first return value's offset.
5853- */
5854- PUSH_OFFSET_TYPE (func_type -> types [func_type -> param_count + i ]);
5856+ /* Here we emit each return value's dynamic_offset. But in fact
5857+ * these offsets are continuous, so interpreter only need to get
5858+ * the first return value's offset.
5859+ */
5860+ PUSH_OFFSET_TYPE (func_type -> types [func_type -> param_count + i ]);
58555861#endif
5862+ }
5863+ }
5864+ else {
5865+ char * type_str [] = { "f64" , "f32" , "i64" , "i32" };
5866+ uint8 type ;
5867+ if (func_type -> result_count != func -> func_type -> result_count ) {
5868+ set_error_buf_v (error_buf , error_buf_size ,
5869+ "%s%u%s" , "type mismatch: expect " ,
5870+ func -> func_type -> result_count ,
5871+ " return values but got other" );
5872+ goto fail ;
5873+ }
5874+ for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5875+ type = func -> func_type -> types [func -> func_type -> param_count + i ];
5876+ if (func_type -> types [func_type -> param_count + i ] != type ) {
5877+ set_error_buf_v (error_buf , error_buf_size ,
5878+ "%s%s%s" , "type mismatch: expect " ,
5879+ type_str [type - VALUE_TYPE_F64 ],
5880+ " but got other" );
5881+ goto fail ;
5882+ }
5883+ }
5884+ RESET_STACK ();
5885+ SET_CUR_BLOCK_STACK_POLYMORPHIC_STATE (true);
58565886 }
5857-
58585887 func -> has_op_func_call = true;
58595888 break ;
58605889 }
58615890
58625891 case WASM_OP_CALL_INDIRECT :
5892+ case WASM_OP_RETURN_CALL_INDIRECT :
58635893 {
58645894 int32 idx ;
58655895 WASMType * func_type ;
@@ -5904,13 +5934,36 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
59045934 }
59055935 }
59065936
5907- for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5908- PUSH_TYPE (func_type -> types [func_type -> param_count + i ]);
5937+ if (opcode == WASM_OP_CALL ) {
5938+ for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5939+ PUSH_TYPE (func_type -> types [func_type -> param_count + i ]);
59095940#if WASM_ENABLE_FAST_INTERP != 0
5910- PUSH_OFFSET_TYPE (func_type -> types [func_type -> param_count + i ]);
5941+ PUSH_OFFSET_TYPE (func_type -> types [func_type -> param_count + i ]);
59115942#endif
5943+ }
5944+ }
5945+ else {
5946+ char * type_str [] = { "f64" , "f32" , "i64" , "i32" };
5947+ uint8 type ;
5948+ if (func_type -> result_count != func -> func_type -> result_count ) {
5949+ set_error_buf_v (error_buf , error_buf_size ,
5950+ "%s%u%s" , "type mismatch: expect " ,
5951+ func -> func_type -> result_count ,
5952+ " return values but got other" );
5953+ goto fail ;
5954+ }
5955+ for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5956+ type = func -> func_type -> types [func -> func_type -> param_count + i ];
5957+ if (func_type -> types [func_type -> param_count + i ] != type )
5958+ set_error_buf_v (error_buf , error_buf_size , "%s%s%s" ,
5959+ "type mismatch: expect " ,
5960+ type_str [type - VALUE_TYPE_F64 ],
5961+ " but got other" );
5962+ goto fail ;
5963+ }
5964+ RESET_STACK ();
5965+ SET_CUR_BLOCK_STACK_POLYMORPHIC_STATE (true);
59125966 }
5913-
59145967 func -> has_op_func_call = true;
59155968 break ;
59165969 }
0 commit comments