@@ -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,12 @@ 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);
632+ const auto called_func_num_args = called_func.inputs .size ();
633+ const auto called_func_num_ret = called_func.outputs .size ();
632634
633- if (!invoke_function (called_func_num_args, called_func_idx, instance, stack, ctx))
635+ if (!invoke_function (called_func_num_args, called_func_num_ret, called_func_idx,
636+ instance, stack, ctx))
634637 goto trap;
635638 break ;
636639 }
@@ -656,8 +659,8 @@ ExecutionResult execute(
656659 if (expected_type != actual_type)
657660 goto trap;
658661
659- if (!invoke_function (actual_type.inputs .size (), called_func. func_idx ,
660- *called_func.instance , stack, ctx))
662+ if (!invoke_function (actual_type.inputs .size (), actual_type. outputs . size () ,
663+ called_func. func_idx , *called_func.instance , stack, ctx))
661664 goto trap;
662665 break ;
663666 }
0 commit comments