From 790bc0472552d80671bdf99ba7652876c463d526 Mon Sep 17 00:00:00 2001 From: "Soni L." Date: Tue, 24 Sep 2024 15:17:18 -0300 Subject: [PATCH] Fix call_ref on empty stack (#2472) Same issue as #2471 but for `call_ref`. We don't believe there's a prior issue for this. --- src/type-checker.cc | 15 ++++----------- test/typecheck/bad-callref-empty.txt | 14 ++++++++++++++ test/typecheck/bad-callref-int32.txt | 2 +- test/typecheck/bad-callref-null.txt | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 test/typecheck/bad-callref-empty.txt diff --git a/src/type-checker.cc b/src/type-checker.cc index 37412e15e5..8d6c3a11f2 100644 --- a/src/type-checker.cc +++ b/src/type-checker.cc @@ -522,21 +522,14 @@ Result TypeChecker::OnCallIndirect(const TypeVector& param_types, Result TypeChecker::OnIndexedFuncRef(Index* out_index) { Type type; - CHECK_RESULT(PeekType(0, &type)); - Result result = Result::Ok; - if (!(type == Type::Any || type.IsReferenceWithIndex())) { - TypeVector actual; - actual.push_back(type); - std::string message = - "type mismatch in call_ref, expected reference but got " + - TypesToString(actual); - PrintError("%s", message.c_str()); - result = Result::Error; + Result result = PeekType(0, &type); + if (!type.IsReferenceWithIndex()) { + type = Type::Reference; } + result |= PopAndCheck1Type(type, "call_ref"); if (Succeeded(result)) { *out_index = type.GetReferenceIndex(); } - result |= DropTypes(1); return result; } diff --git a/test/typecheck/bad-callref-empty.txt b/test/typecheck/bad-callref-empty.txt new file mode 100644 index 0000000000..cee3885352 --- /dev/null +++ b/test/typecheck/bad-callref-empty.txt @@ -0,0 +1,14 @@ +;;; TOOL: wat2wasm +;;; ARGS: --enable-function-references +;;; ERROR: 1 +(module + (func (export "main") + (call_ref + ) + ) +) +(;; STDERR ;;; +out/test/typecheck/bad-callref-empty.txt:6:6: error: type mismatch in call_ref, expected [reference] but got [] + (call_ref + ^^^^^^^^ +;;; STDERR ;;) diff --git a/test/typecheck/bad-callref-int32.txt b/test/typecheck/bad-callref-int32.txt index 52f34da1d8..95401b9504 100644 --- a/test/typecheck/bad-callref-int32.txt +++ b/test/typecheck/bad-callref-int32.txt @@ -9,7 +9,7 @@ ) ) (;; STDERR ;;; -out/test/typecheck/bad-callref-int32.txt:6:6: error: type mismatch in call_ref, expected reference but got [i32] +out/test/typecheck/bad-callref-int32.txt:6:6: error: type mismatch in call_ref, expected [reference] but got [... i32] (call_ref (i32.const 10) ^^^^^^^^ ;;; STDERR ;;) diff --git a/test/typecheck/bad-callref-null.txt b/test/typecheck/bad-callref-null.txt index 0886077738..6771a89367 100644 --- a/test/typecheck/bad-callref-null.txt +++ b/test/typecheck/bad-callref-null.txt @@ -9,7 +9,7 @@ ) ) (;; STDERR ;;; -out/test/typecheck/bad-callref-null.txt:6:6: error: type mismatch in call_ref, expected reference but got [funcref] +out/test/typecheck/bad-callref-null.txt:6:6: error: type mismatch in call_ref, expected [reference] but got [... funcref] (call_ref (i32.const 10) ^^^^^^^^ ;;; STDERR ;;)