@@ -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,6 +5797,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
57955797 {
57965798 int32 idx ;
57975799 uint8 ret_type ;
5800+
57985801 for (idx = (int32 )func -> func_type -> result_count - 1 ; idx >= 0 ; idx -- ) {
57995802 ret_type = * (func -> func_type -> types
58005803 + func -> func_type -> param_count + idx );
@@ -5812,6 +5815,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
58125815 }
58135816
58145817 case WASM_OP_CALL :
5818+ #if WASM_ENABLE_TAIL_CALL != 0
5819+ case WASM_OP_RETURN_CALL :
5820+ #endif
58155821 {
58165822 WASMType * func_type ;
58175823 uint32 func_idx ;
@@ -5844,22 +5850,53 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
58445850 }
58455851 }
58465852
5847- for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5848- PUSH_TYPE (func_type -> types [func_type -> param_count + i ]);
5853+ #if WASM_ENABLE_TAIL_CALL != 0
5854+ if (opcode == WASM_OP_CALL ) {
5855+ #endif
5856+ for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5857+ PUSH_TYPE (func_type -> types [func_type -> param_count + i ]);
58495858#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 ]);
5859+ /* Here we emit each return value's dynamic_offset. But in fact
5860+ * these offsets are continuous, so interpreter only need to get
5861+ * the first return value's offset.
5862+ */
5863+ PUSH_OFFSET_TYPE (func_type -> types [func_type -> param_count + i ]);
58555864#endif
5865+ }
5866+ #if WASM_ENABLE_TAIL_CALL != 0
58565867 }
5857-
5868+ else {
5869+ char * type_str [] = { "f64" , "f32" , "i64" , "i32" };
5870+ uint8 type ;
5871+ if (func_type -> result_count != func -> func_type -> result_count ) {
5872+ set_error_buf_v (error_buf , error_buf_size ,
5873+ "%s%u%s" , "type mismatch: expect " ,
5874+ func -> func_type -> result_count ,
5875+ " return values but got other" );
5876+ goto fail ;
5877+ }
5878+ for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5879+ type = func -> func_type -> types [func -> func_type -> param_count + i ];
5880+ if (func_type -> types [func_type -> param_count + i ] != type ) {
5881+ set_error_buf_v (error_buf , error_buf_size ,
5882+ "%s%s%s" , "type mismatch: expect " ,
5883+ type_str [type - VALUE_TYPE_F64 ],
5884+ " but got other" );
5885+ goto fail ;
5886+ }
5887+ }
5888+ RESET_STACK ();
5889+ SET_CUR_BLOCK_STACK_POLYMORPHIC_STATE (true);
5890+ }
5891+ #endif
58585892 func -> has_op_func_call = true;
58595893 break ;
58605894 }
58615895
58625896 case WASM_OP_CALL_INDIRECT :
5897+ #if WASM_ENABLE_TAIL_CALL != 0
5898+ case WASM_OP_RETURN_CALL_INDIRECT :
5899+ #endif
58635900 {
58645901 int32 idx ;
58655902 WASMType * func_type ;
@@ -5904,13 +5941,40 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
59045941 }
59055942 }
59065943
5907- for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5908- PUSH_TYPE (func_type -> types [func_type -> param_count + i ]);
5944+ #if WASM_ENABLE_TAIL_CALL != 0
5945+ if (opcode == WASM_OP_CALL ) {
5946+ #endif
5947+ for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5948+ PUSH_TYPE (func_type -> types [func_type -> param_count + i ]);
59095949#if WASM_ENABLE_FAST_INTERP != 0
5910- PUSH_OFFSET_TYPE (func_type -> types [func_type -> param_count + i ]);
5950+ PUSH_OFFSET_TYPE (func_type -> types [func_type -> param_count + i ]);
59115951#endif
5952+ }
5953+ #if WASM_ENABLE_TAIL_CALL != 0
59125954 }
5913-
5955+ else {
5956+ char * type_str [] = { "f64" , "f32" , "i64" , "i32" };
5957+ uint8 type ;
5958+ if (func_type -> result_count != func -> func_type -> result_count ) {
5959+ set_error_buf_v (error_buf , error_buf_size ,
5960+ "%s%u%s" , "type mismatch: expect " ,
5961+ func -> func_type -> result_count ,
5962+ " return values but got other" );
5963+ goto fail ;
5964+ }
5965+ for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5966+ type = func -> func_type -> types [func -> func_type -> param_count + i ];
5967+ if (func_type -> types [func_type -> param_count + i ] != type )
5968+ set_error_buf_v (error_buf , error_buf_size , "%s%s%s" ,
5969+ "type mismatch: expect " ,
5970+ type_str [type - VALUE_TYPE_F64 ],
5971+ " but got other" );
5972+ goto fail ;
5973+ }
5974+ RESET_STACK ();
5975+ SET_CUR_BLOCK_STACK_POLYMORPHIC_STATE (true);
5976+ }
5977+ #endif
59145978 func -> has_op_func_call = true;
59155979 break ;
59165980 }
0 commit comments