From 9d41135fe30df498be4e9fb426a8e8d8cf71f9f3 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 17 May 2018 20:39:19 -0700 Subject: [PATCH] Translate from function-body index to function-index-space index. The wasm function index space consists of the index space of the imported functions concatenated with the index space of the defined functions. When iterating through function definitions, it's necessary to adjust the index when a function-index-space index is needed. --- lib/runtime/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/runtime/src/lib.rs b/lib/runtime/src/lib.rs index 45a3ac8c3a..e8e5d54600 100644 --- a/lib/runtime/src/lib.rs +++ b/lib/runtime/src/lib.rs @@ -569,7 +569,8 @@ impl<'data, 'module> ModuleTranslation<'data, 'module> { ) -> Result<(Compilation<'module>, Relocations), String> { let mut functions = Vec::new(); let mut relocations = Vec::new(); - for (func_index, input) in self.lazy.function_body_inputs.iter().enumerate() { + for (i, input) in self.lazy.function_body_inputs.iter().enumerate() { + let func_index = i + self.module.imported_funcs.len(); let mut context = cretonne_codegen::Context::new(); context.func.name = get_func_name(func_index); context.func.signature = self.module.signatures[self.module.functions[func_index]]