summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/shared-validator.cc9
-rw-r--r--test/spec/ref_func.txt14
2 files changed, 8 insertions, 15 deletions
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);
}
diff --git a/test/spec/ref_func.txt b/test/spec/ref_func.txt
index b9d7dc2e..4bc1a16a 100644
--- a/test/spec/ref_func.txt
+++ b/test/spec/ref_func.txt
@@ -1,19 +1,6 @@
;;; TOOL: run-interp-spec
;;; STDIN_FILE: third_party/testsuite/ref_func.wast
(;; STDERR ;;;
-out/test/spec/ref_func.wast:90:29: error: function 0 is not declared in any elem sections
- (global funcref (ref.func $f1))
- ^^^
-out/test/spec/ref_func.wast:98:15: error: function 0 is not declared in any elem sections
- (ref.func $f1)
- ^^^
-out/test/spec/ref_func.wast:99:15: error: function 1 is not declared in any elem sections
- (ref.func $f2)
- ^^^
-0000000: error: function 0 is not declared in any elem sections
-0000000: error: function 0 is not declared in any elem sections
-0000000: error: function 1 is not declared in any elem sections
-0000069: error: EndModule callback failed
;;; STDERR ;;)
(;; STDOUT ;;;
set-g() =>
@@ -21,7 +8,6 @@ set-f() =>
out/test/spec/ref_func.wast:69: assert_invalid passed:
0000000: error: function variable out of range: 7 (max 2)
0000026: error: OnRefFuncExpr callback failed
-out/test/spec/ref_func.wast:80: error reading module: "out/test/spec/ref_func/ref_func.3.wasm"
out/test/spec/ref_func.wast:109: assert_invalid passed:
0000000: error: function 0 is not declared in any elem sections
000001b: error: EndModule callback failed