Skip to content

Commit 75a4a52

Browse files
committed
[test] Add test for local.tee re WebAssembly#516
1 parent d871d12 commit 75a4a52

File tree

2 files changed

+39
-39
lines changed

2 files changed

+39
-39
lines changed

test/core/br_on_null.wast

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -65,45 +65,30 @@
6565
(assert_return (invoke "args-null" (i32.const 3)) (i32.const 3))
6666
(assert_return (invoke "args-f" (i32.const 3)) (i32.const 9))
6767

68+
6869
;; https://github.com/WebAssembly/gc/issues/516
70+
;; Tests that validators are correctly doing
71+
;;
72+
;; pop_operands(label_types)
73+
;; push_operands(label_types)
74+
;;
75+
;; for validating br_on_null, rather than incorrectly doing either
76+
;;
77+
;; push_operands(pop_operands(label_types))
78+
;;
79+
;; or just inspecting the types on the stack without any pushing or
80+
;; popping, neither of which handle subtyping correctly.
6981
(assert_invalid
70-
(module
71-
(type $ty (func))
72-
73-
(func $ty_ref_to_func_ref (param (ref null $ty)) (result funcref)
74-
local.get 0
75-
)
76-
77-
(func (param funcref) (result funcref)
78-
ref.null $ty
79-
local.get 0
80-
81-
;; This instruction is typed `[funcref funcref] -> [funcref (ref
82-
;; func)]`. The stack coming into this instruction is `[(ref null $ty)
83-
;; funcref]` which matches because of `(ref null $ty) <: funcref`. However,
84-
;; that subtyping relation doesn't mean that this instruction can *push* a
85-
;; `(ref null $ty)`. The label type effectively erases the `(ref null
86-
;; $ty)`, turning it into an `funcref`. Finally, a type mismatch error
87-
;; should be reported at the `call` instruction below, which expects a
88-
;; `(ref null $ty)` but is given the `funcref` (that is "actually" a `(ref
89-
;; null $ty)`).
90-
;;
91-
;; This tests that validators are correctly doing
92-
;;
93-
;; pop_operands(label_types)
94-
;; push_operands(label_types)
95-
;;
96-
;; rather than incorrectly doing either
97-
;;
98-
;; push_operands(pop_operands(label_types))
99-
;;
100-
;; or just inspecting the types on the stack without any pushing or
101-
;; popping, neither of which handle subtyping correctly.
102-
br_on_null 0
103-
104-
drop
105-
call $ty_ref_to_func_ref
106-
)
107-
)
108-
"type mismatch"
82+
(module
83+
(type $t (func))
84+
(func $f (param (ref null $t)) (result funcref) (local.get 0))
85+
(func (param funcref) (result funcref)
86+
(ref.null $t)
87+
(local.get 0)
88+
(br_on_null 0) ;; only leaves two funcref's on the stack
89+
(drop)
90+
(call $f)
91+
)
92+
)
93+
"type mismatch"
10994
)

test/core/local_tee.wast

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,21 @@
608608
"type mismatch"
609609
)
610610

611+
;; https://github.com/WebAssembly/gc/issues/516
612+
(assert_invalid
613+
(module
614+
(type $t (func))
615+
(func $f (param (ref null $t)))
616+
(func
617+
(local $x funcref)
618+
(ref.null $t)
619+
(local.tee $x) ;; leaves only a funcref on the stack
620+
(call $f)
621+
)
622+
)
623+
"type mismatch"
624+
)
625+
611626

612627
;; Invalid local index
613628

0 commit comments

Comments
 (0)