Skip to content
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
13 changes: 11 additions & 2 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,13 @@ struct FunctionValidator : public WalkerPass<PostWalker<FunctionValidator>> {
Type(Type::unreachable),
printable,
"return_call* should have unreachable type");
auto* func = getFunction();
if (!shouldBeTrue(!!func, curr, "function not defined")) {
return;
}
shouldBeSubType(
sig.results,
getFunction()->getResults(),
func->getResults(),
printable,
"return_call* callee return type must match caller return type");
} else {
Expand Down Expand Up @@ -696,7 +700,12 @@ void FunctionValidator::visitBlock(Block* curr) {
}
breakTypes.erase(iter);
}
switch (getFunction()->profile) {

auto* func = getFunction();
if (!shouldBeTrue(!!func, curr, "function not defined")) {
return;
}
switch (func->profile) {
case IRProfile::Normal:
validateNormalBlockElements(curr);
break;
Expand Down
14 changes: 14 additions & 0 deletions test/lit/validation/function-missing.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
;; Test that we validate functions declaration and usage for globals.

;; RUN: not wasm-opt %s -all 2>&1 | filecheck %s

(module
;; CHECK: function not defined
(global (mut i32) (block))

;; CHECK: function not defined
(global (mut i32) (return_call 0))

(func $0
)
)