@@ -3307,10 +3307,16 @@ wasm_loader_find_block_addr(BlockAddr *block_addr_cache,
33073307 break ;
33083308
33093309 case WASM_OP_CALL :
3310+ #if WASM_ENABLE_TAIL_CALL != 0
3311+ case WASM_OP_RETURN_CALL :
3312+ #endif
33103313 skip_leb_uint32 (p , p_end ); /* funcidx */
33113314 break ;
33123315
33133316 case WASM_OP_CALL_INDIRECT :
3317+ #if WASM_ENABLE_TAIL_CALL != 0
3318+ case WASM_OP_RETURN_CALL_INDIRECT :
3319+ #endif
33143320 skip_leb_uint32 (p , p_end ); /* typeidx */
33153321 CHECK_BUF (p , p_end , 1 );
33163322 u8 = read_uint8 (p ); /* 0x00 */
@@ -5812,6 +5818,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
58125818 }
58135819
58145820 case WASM_OP_CALL :
5821+ #if WASM_ENABLE_TAIL_CALL != 0
5822+ case WASM_OP_RETURN_CALL :
5823+ #endif
58155824 {
58165825 WASMType * func_type ;
58175826 uint32 func_idx ;
@@ -5844,22 +5853,53 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
58445853 }
58455854 }
58465855
5847- for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5848- PUSH_TYPE (func_type -> types [func_type -> param_count + i ]);
5856+ #if WASM_ENABLE_TAIL_CALL != 0
5857+ if (opcode == WASM_OP_CALL ) {
5858+ #endif
5859+ for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5860+ PUSH_TYPE (func_type -> types [func_type -> param_count + i ]);
58495861#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 ]);
5862+ /* Here we emit each return value's dynamic_offset. But in fact
5863+ * these offsets are continuous, so interpreter only need to get
5864+ * the first return value's offset.
5865+ */
5866+ PUSH_OFFSET_TYPE (func_type -> types [func_type -> param_count + i ]);
58555867#endif
5868+ }
5869+ #if WASM_ENABLE_TAIL_CALL != 0
58565870 }
5857-
5871+ else {
5872+ char * type_str [] = { "f64" , "f32" , "i64" , "i32" };
5873+ uint8 type ;
5874+ if (func_type -> result_count != func -> func_type -> result_count ) {
5875+ set_error_buf_v (error_buf , error_buf_size ,
5876+ "%s%u%s" , "type mismatch: expect " ,
5877+ func -> func_type -> result_count ,
5878+ " return values but got other" );
5879+ goto fail ;
5880+ }
5881+ for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5882+ type = func -> func_type -> types [func -> func_type -> param_count + i ];
5883+ if (func_type -> types [func_type -> param_count + i ] != type ) {
5884+ set_error_buf_v (error_buf , error_buf_size ,
5885+ "%s%s%s" , "type mismatch: expect " ,
5886+ type_str [type - VALUE_TYPE_F64 ],
5887+ " but got other" );
5888+ goto fail ;
5889+ }
5890+ }
5891+ RESET_STACK ();
5892+ SET_CUR_BLOCK_STACK_POLYMORPHIC_STATE (true);
5893+ }
5894+ #endif
58585895 func -> has_op_func_call = true;
58595896 break ;
58605897 }
58615898
58625899 case WASM_OP_CALL_INDIRECT :
5900+ #if WASM_ENABLE_TAIL_CALL != 0
5901+ case WASM_OP_RETURN_CALL_INDIRECT :
5902+ #endif
58635903 {
58645904 int32 idx ;
58655905 WASMType * func_type ;
@@ -5904,13 +5944,40 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
59045944 }
59055945 }
59065946
5907- for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5908- PUSH_TYPE (func_type -> types [func_type -> param_count + i ]);
5947+ #if WASM_ENABLE_TAIL_CALL != 0
5948+ if (opcode == WASM_OP_CALL ) {
5949+ #endif
5950+ for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5951+ PUSH_TYPE (func_type -> types [func_type -> param_count + i ]);
59095952#if WASM_ENABLE_FAST_INTERP != 0
5910- PUSH_OFFSET_TYPE (func_type -> types [func_type -> param_count + i ]);
5953+ PUSH_OFFSET_TYPE (func_type -> types [func_type -> param_count + i ]);
59115954#endif
5955+ }
5956+ #if WASM_ENABLE_TAIL_CALL != 0
59125957 }
5913-
5958+ else {
5959+ char * type_str [] = { "f64" , "f32" , "i64" , "i32" };
5960+ uint8 type ;
5961+ if (func_type -> result_count != func -> func_type -> result_count ) {
5962+ set_error_buf_v (error_buf , error_buf_size ,
5963+ "%s%u%s" , "type mismatch: expect " ,
5964+ func -> func_type -> result_count ,
5965+ " return values but got other" );
5966+ goto fail ;
5967+ }
5968+ for (i = 0 ; i < func_type -> result_count ; i ++ ) {
5969+ type = func -> func_type -> types [func -> func_type -> param_count + i ];
5970+ if (func_type -> types [func_type -> param_count + i ] != type )
5971+ set_error_buf_v (error_buf , error_buf_size , "%s%s%s" ,
5972+ "type mismatch: expect " ,
5973+ type_str [type - VALUE_TYPE_F64 ],
5974+ " but got other" );
5975+ goto fail ;
5976+ }
5977+ RESET_STACK ();
5978+ SET_CUR_BLOCK_STACK_POLYMORPHIC_STATE (true);
5979+ }
5980+ #endif
59145981 func -> has_op_func_call = true;
59155982 break ;
59165983 }
0 commit comments