Skip to content

Commit

Permalink
Add back the assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed May 30, 2022
1 parent 3ccac17 commit aef6502
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/fizzy/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ void branch(const Code& code, OperandStack& stack, const uint8_t*& pc, uint32_t
stack.drop(stack_drop);
}

inline bool invoke_function(size_t num_args, uint32_t func_idx, Instance& instance,
OperandStack& stack, ExecutionContext& ctx) noexcept
inline bool invoke_function(size_t num_args, [[maybe_unused]] size_t num_ret, uint32_t func_idx,
Instance& instance, OperandStack& stack, ExecutionContext& ctx) noexcept
{
assert(stack.size() >= num_args);
const auto call_args = stack.rend() - num_args;
Expand All @@ -524,6 +524,7 @@ inline bool invoke_function(size_t num_args, uint32_t func_idx, Instance& instan
stack.drop(num_args);

// NOTE: validation ensures there is at most 1 output value
assert(num_ret == (ret.has_value ? 1 : 0));
// Push back the result
if (ret.has_value)
stack.push(ret.value);
Expand Down Expand Up @@ -627,10 +628,10 @@ ExecutionResult execute(
case Instr::call:
{
const auto called_func_idx = read<uint32_t>(pc);
const auto called_func_num_args =
instance.module->get_function_type(called_func_idx).inputs.size();
const auto called_func = instance.module->get_function_type(called_func_idx);

if (!invoke_function(called_func_num_args, called_func_idx, instance, stack, ctx))
if (!invoke_function(called_func.inputs.size(), called_func.outputs.size(),
called_func_idx, instance, stack, ctx))
goto trap;
break;
}
Expand All @@ -656,8 +657,8 @@ ExecutionResult execute(
if (expected_type != actual_type)
goto trap;

if (!invoke_function(actual_type.inputs.size(), called_func.func_idx,
*called_func.instance, stack, ctx))
if (!invoke_function(actual_type.inputs.size(), actual_type.outputs.size(),
called_func.func_idx, *called_func.instance, stack, ctx))
goto trap;
break;
}
Expand Down

0 comments on commit aef6502

Please sign in to comment.