@@ -510,8 +510,8 @@ void branch(const Code& code, OperandStack& stack, const uint8_t*& pc, uint32_t
510510 stack.drop (stack_drop);
511511}
512512
513- inline bool invoke_function (size_t num_args, uint32_t func_idx, Instance& instance ,
514- OperandStack& stack, ExecutionContext& ctx) noexcept
513+ inline bool invoke_function (size_t num_args, [[maybe_unused]] size_t num_ret, uint32_t func_idx ,
514+ Instance& instance, OperandStack& stack, ExecutionContext& ctx) noexcept
515515{
516516 assert (stack.size () >= num_args);
517517 const auto call_args = stack.rend () - num_args;
@@ -524,6 +524,7 @@ inline bool invoke_function(size_t num_args, uint32_t func_idx, Instance& instan
524524 stack.drop (num_args);
525525
526526 // NOTE: validation ensures there is at most 1 output value
527+ assert (num_ret == (ret.has_value ? 1 : 0 ));
527528 // Push back the result
528529 if (ret.has_value )
529530 stack.push (ret.value );
@@ -627,10 +628,10 @@ ExecutionResult execute(
627628 case Instr::call:
628629 {
629630 const auto called_func_idx = read<uint32_t >(pc);
630- const auto called_func_num_args =
631- instance.module ->get_function_type (called_func_idx).inputs .size ();
631+ const auto called_func = instance.module ->get_function_type (called_func_idx);
632632
633- if (!invoke_function (called_func_num_args, called_func_idx, instance, stack, ctx))
633+ if (!invoke_function (called_func.inputs .size (), called_func.outputs .size (),
634+ called_func_idx, instance, stack, ctx))
634635 goto trap;
635636 break ;
636637 }
@@ -656,8 +657,8 @@ ExecutionResult execute(
656657 if (expected_type != actual_type)
657658 goto trap;
658659
659- if (!invoke_function (actual_type.inputs .size (), called_func. func_idx ,
660- *called_func.instance , stack, ctx))
660+ if (!invoke_function (actual_type.inputs .size (), actual_type. outputs . size () ,
661+ called_func. func_idx , *called_func.instance , stack, ctx))
661662 goto trap;
662663 break ;
663664 }
0 commit comments