Skip to content

Commit

Permalink
Fix call_ref on empty stack
Browse files Browse the repository at this point in the history
  • Loading branch information
SoniEx2 committed Sep 24, 2024
1 parent 3852498 commit b9c687f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
15 changes: 4 additions & 11 deletions src/type-checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
14 changes: 14 additions & 0 deletions test/typecheck/bad-callref-empty.txt
Original file line number Diff line number Diff line change
@@ -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 ;;)
2 changes: 1 addition & 1 deletion test/typecheck/bad-callref-int32.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;;)
2 changes: 1 addition & 1 deletion test/typecheck/bad-callref-null.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;;)

0 comments on commit b9c687f

Please sign in to comment.