Skip to content

Commit da615cc

Browse files
committed
[test] More tests for stack typing re WebAssembly#516
1 parent 75a4a52 commit da615cc

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed

interpreter/valid/valid.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ let check_stack (c : context) ts1 ts2 at =
233233
" but stack has " ^ string_of_result_type ts1)
234234

235235
let pop c (ell1, ts1) (ell2, ts2) at =
236+
Printf.eprintf "[pop] %s\n%!"
237+
(String.concat " " (List.map string_of_val_type ts1));
236238
let n1 = List.length ts1 in
237239
let n2 = List.length ts2 in
238240
let n = min n1 n2 in
@@ -241,6 +243,8 @@ let pop c (ell1, ts1) (ell2, ts2) at =
241243
(ell2, if ell1 = Ellipses then [] else Lib.List.take (n2 - n) ts2)
242244

243245
let push c (ell1, ts1) (ell2, ts2) =
246+
Printf.eprintf "[push] %s\n%!"
247+
(String.concat " " (List.map string_of_val_type ts1));
244248
assert (ell1 = NoEllipses || ts2 = []);
245249
(if ell1 = Ellipses || ell2 = Ellipses then Ellipses else NoEllipses),
246250
ts2 @ ts1
@@ -891,12 +895,14 @@ and check_seq (c : context) (s : infer_result_type) (es : instr list)
891895
s, []
892896

893897
| e::es' ->
898+
Printf.eprintf "---- %s%!" (Sexpr.to_string 80 (Arrange.instr e));
894899
let {ins; outs}, xs = check_instr c e s in
895900
check_seq (init_locals c xs) (push c outs (pop c ins s e.at)) es'
896901

897902
and check_block (c : context) (es : instr list) (it : instr_type) at =
898903
let InstrT (ts1, ts2, _xs) = it in
899904
let s, xs' = check_seq c (stack ts1) es in
905+
Printf.eprintf "---- end\n%!";
900906
let s' = pop c (stack ts2) s at in
901907
require (snd s' = []) at
902908
("type mismatch: block requires " ^ string_of_result_type ts2 ^

test/core/br_if.wast

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,3 +663,17 @@
663663
"unknown label"
664664
)
665665

666+
;; https://github.com/WebAssembly/gc/issues/516
667+
(assert_invalid
668+
(module
669+
(type $t (func))
670+
(func $f (param (ref null $t)) (result funcref) (local.get 0))
671+
(func (result funcref)
672+
(ref.null $t)
673+
(i32.const 0)
674+
(br_if 0) ;; only leaves funcref on the stack
675+
(call $f)
676+
)
677+
)
678+
"type mismatch"
679+
)

test/core/br_on_non_null.wast

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,20 @@
7171

7272
(assert_return (invoke "args-null" (i32.const 3)) (i32.const 3))
7373
(assert_return (invoke "args-f" (i32.const 3)) (i32.const 9))
74+
75+
76+
;; https://github.com/WebAssembly/gc/issues/516
77+
(assert_invalid
78+
(module
79+
(type $t (func))
80+
(func $f (param (ref null $t)) (result funcref) (local.get 0))
81+
(func (param funcref) (result funcref funcref)
82+
(ref.null $t)
83+
(local.get 0)
84+
(br_on_non_null 0) ;; only leaves a funcref on the stack
85+
(call $f)
86+
(local.get 0)
87+
)
88+
)
89+
"type mismatch"
90+
)

test/core/gc/br_on_cast.wast

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,21 @@
265265
)
266266
"type mismatch"
267267
)
268+
269+
270+
;; https://github.com/WebAssembly/gc/issues/516
271+
(assert_invalid
272+
(module
273+
(type $t (func))
274+
(func $f (param (ref null $t)) (result funcref) (local.get 0))
275+
(func (param funcref) (result funcref funcref)
276+
(ref.null $t)
277+
(local.get 0)
278+
(br_on_cast 0 funcref (ref $t)) ;; only leaves two funcref's on the stack
279+
(drop)
280+
(call $f)
281+
(local.get 0)
282+
)
283+
)
284+
"type mismatch"
285+
)

test/core/gc/br_on_cast_fail.wast

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,21 @@
280280
)
281281
"type mismatch"
282282
)
283+
284+
285+
;; https://github.com/WebAssembly/gc/issues/516
286+
(assert_invalid
287+
(module
288+
(type $t (func))
289+
(func $f (param (ref null $t)) (result funcref) (local.get 0))
290+
(func (param funcref) (result funcref funcref)
291+
(ref.null $t)
292+
(local.get 0)
293+
(br_on_cast_fail 0 funcref (ref $t)) ;; only leaves two funcref's on the stack
294+
(drop)
295+
(call $f)
296+
(local.get 0)
297+
)
298+
)
299+
"type mismatch"
300+
)

0 commit comments

Comments
 (0)