From 3ccac1723ff39f3d1700e789938c4e4d30783de0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 1 Oct 2020 13:37:31 +0200 Subject: [PATCH] Pass only number of args to invoke_function() --- lib/fizzy/execute.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/fizzy/execute.cpp b/lib/fizzy/execute.cpp index 1650a24e8..10ffe7673 100644 --- a/lib/fizzy/execute.cpp +++ b/lib/fizzy/execute.cpp @@ -510,10 +510,9 @@ void branch(const Code& code, OperandStack& stack, const uint8_t*& pc, uint32_t stack.drop(stack_drop); } -inline bool invoke_function(const FuncType& func_type, uint32_t func_idx, Instance& instance, +inline bool invoke_function(size_t num_args, uint32_t func_idx, Instance& instance, OperandStack& stack, ExecutionContext& ctx) noexcept { - const auto num_args = func_type.inputs.size(); assert(stack.size() >= num_args); const auto call_args = stack.rend() - num_args; @@ -525,7 +524,6 @@ inline bool invoke_function(const FuncType& func_type, uint32_t func_idx, Instan stack.drop(num_args); // NOTE: validation ensures there is at most 1 output value - assert(func_type.outputs.size() == (ret.has_value ? 1 : 0)); // Push back the result if (ret.has_value) stack.push(ret.value); @@ -629,9 +627,10 @@ ExecutionResult execute( case Instr::call: { const auto called_func_idx = read(pc); - const auto& called_func_type = instance.module->get_function_type(called_func_idx); + const auto called_func_num_args = + instance.module->get_function_type(called_func_idx).inputs.size(); - if (!invoke_function(called_func_type, called_func_idx, instance, stack, ctx)) + if (!invoke_function(called_func_num_args, called_func_idx, instance, stack, ctx)) goto trap; break; } @@ -657,8 +656,8 @@ ExecutionResult execute( if (expected_type != actual_type) goto trap; - if (!invoke_function( - actual_type, called_func.func_idx, *called_func.instance, stack, ctx)) + if (!invoke_function(actual_type.inputs.size(), called_func.func_idx, + *called_func.instance, stack, ctx)) goto trap; break; }