From d08b0d9fd2b76325b09308268e14969f923ff1fe Mon Sep 17 00:00:00 2001 From: Asumu Takikawa Date: Wed, 13 Apr 2022 11:31:45 -0700 Subject: Fix checking of ref.func index declarations (#1894) The validation was overly strict for ref.func index uses. In the spec, the ref index just needs to appear in "the set of function indices occurring in the module, except in its functions or start function." which includes uses in the global and export sections. Fixes issue #1893 --- src/shared-validator.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/shared-validator.cc') diff --git a/src/shared-validator.cc b/src/shared-validator.cc index 5d9de4fe..086ca68e 100644 --- a/src/shared-validator.cc +++ b/src/shared-validator.cc @@ -211,6 +211,7 @@ Result SharedValidator::OnExport(const Location& loc, switch (kind) { case ExternalKind::Func: result |= CheckFuncIndex(item_var); + declared_funcs_.insert(item_var.index()); break; case ExternalKind::Table: @@ -951,7 +952,13 @@ Result SharedValidator::OnRefFunc(const Location& loc, Var func_var) { Result result = CheckInstr(Opcode::RefFunc, loc); result |= CheckFuncIndex(func_var); if (Succeeded(result)) { - check_declared_funcs_.push_back(func_var); + // References in initializer expressions are considered declarations, as + // opposed to references in function bodies that are considered usages. + if (in_init_expr_) { + declared_funcs_.insert(func_var.index()); + } else { + check_declared_funcs_.push_back(func_var); + } Index func_type = GetFunctionTypeIndex(func_var.index()); result |= typechecker_.OnRefFuncExpr(func_type); } -- cgit v1.2.3