Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix call_ref on empty stack #2472

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it OK to use type here even if PeekType fails? i.e. should we return early if PeekType fails?

Copy link
Contributor Author

@SoniEx2 SoniEx2 Sep 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is fine. PeekType will set type to Type::Any, this is the same logic as the fix in #2471 - we want the error message.

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 ;;)
Loading