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
12 changes: 7 additions & 5 deletions src/wasm/wasm-validator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,9 @@ struct FunctionValidator : public WalkerPass<PostWalker<FunctionValidator>> {
Type(Type::unreachable),
curr,
"return_call* should have unreachable type");
shouldBeEqual(
getFunction()->getResults(),
shouldBeSubType(
sig.results,
getFunction()->getResults(),
curr,
"return_call* callee return type must match caller return type");
} else {
Expand Down Expand Up @@ -798,9 +798,11 @@ void FunctionValidator::visitCallIndirect(CallIndirect* curr) {
if (curr->target->type != Type::unreachable) {
auto* table = getModule()->getTableOrNull(curr->table);
shouldBeTrue(!!table, curr, "call-indirect table must exist");
shouldBeTrue(table->type.isFunction(),
curr,
"call-indirect table must be of function type.");
if (table) {
shouldBeTrue(table->type.isFunction(),
curr,
"call-indirect table must be of function type.");
}
}

validateCallParamsAndResult(curr, curr->sig);
Expand Down
78 changes: 78 additions & 0 deletions test/lit/tail-call.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.

;; Check that tail calls are parsed, validated, and printed correctly

;; RUN: foreach %s %t wasm-opt -all -S -o - | filecheck %s
;; TODO: --nominal as well

(module

;; CHECK: (type $void (func))
(type $void (func))

;; CHECK: (table $t 1 1 funcref)
(table $t 1 1 funcref)

;; CHECK: (elem $e (i32.const 0) $foo)
(elem $e (i32.const 0) $foo)

;; CHECK: (func $foo
;; CHECK-NEXT: (return_call $bar)
;; CHECK-NEXT: )
(func $foo
(return_call $bar)
)

;; CHECK: (func $bar
;; CHECK-NEXT: (return_call_indirect $t (type $void)
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $bar
(return_call_indirect (type $void) (i32.const 0))
)
)

;; Check GC types and subtyping
(module
;; CHECK: (type $return-B (func (result (ref $B))))
(type $return-B (func (result (ref $B))))

;; CHECK: (type $return-A (func (result (ref null $A))))
(type $return-A (func (result (ref null $A))))

;; CHECK: (type $A (struct (field i32)))
(type $A (struct i32))

;; CHECK: (type $B (struct (field i32) (field i32)))
(type $B (struct i32 i32) (supertype $A))

;; CHECK: (table $t 1 1 funcref)
(table $t 1 1 funcref)

;; CHECK: (elem $e (i32.const 0) $callee)
(elem $e (i32.const 0) $callee)

;; CHECK: (func $caller (result (ref null $A))
;; CHECK-NEXT: (return_call $callee)
;; CHECK-NEXT: )
(func $caller (type $return-A)
(return_call $callee)
)

;; CHECK: (func $caller-indirect (result (ref $B))
;; CHECK-NEXT: (return_call_indirect $t (type $return-B)
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $caller-indirect (type $return-B)
(return_call_indirect $t (type $return-B) (i32.const 0))
)

;; CHECK: (func $callee (result (ref $B))
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
(func $callee (type $return-B)
(unreachable)
)
)
11 changes: 0 additions & 11 deletions test/tail-call.wast

This file was deleted.