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 validation of switch. #99

Merged
merged 2 commits into from
Nov 27, 2024
Merged
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
7 changes: 4 additions & 3 deletions interpreter/valid/valid.ml
Original file line number Diff line number Diff line change
@@ -651,14 +651,15 @@ let rec check_instr (c : context) (e : instr) (s : infer_result_type) : infer_in
" but the type annotation has " ^ string_of_result_type ts11)
in
let et = tag c y in
let FuncT (_, t) as ft = func_type_of_tag_type c et y.at in
require (match_func_type c.types (FuncT ([], t)) ft) y.at
let FuncT (ts31, t) = func_type_of_tag_type c et y.at in
require (ts31 = []) y.at
"type mismatch in switch tag";
require (match_result_type c.types ts12 t) y.at
"type mismatch in continuation types";
require (match_result_type c.types t ts22) y.at
"type mismatch in continuation types";
ts11 --> ts21, []
let ts11' = Lib.List.lead ts11 in
(ts11' @ [RefT (Null, VarHT (StatX x.it))]) --> ts21, []

| Throw x ->
let FuncT (ts1, ts2) = func_type_of_tag_type c (tag c x) x.at in
3 changes: 2 additions & 1 deletion test/core/run.py
Original file line number Diff line number Diff line change
@@ -35,7 +35,8 @@
simd_test_files = glob.glob(os.path.join(inputDir, "simd", "*.wast"))
gc_test_files = glob.glob(os.path.join(inputDir, "gc", "*.wast"))
multi_memory_test_files = glob.glob(os.path.join(inputDir, "multi-memory", "*.wast"))
all_test_files = main_test_files + simd_test_files + gc_test_files + multi_memory_test_files
stack_switching_test_files = glob.glob(os.path.join(inputDir, "stack-switching", "*.wast"))
all_test_files = main_test_files + simd_test_files + gc_test_files + multi_memory_test_files + stack_switching_test_files

wasmExec = arguments.wasm
wasmCommand = wasmExec + " " + arguments.opts
37 changes: 36 additions & 1 deletion test/core/stack-switching/cont.wast
Original file line number Diff line number Diff line change
@@ -925,4 +925,39 @@

(elem declare func $even $odd)
)
(assert_return (invoke "main") (i32.const 10))
(assert_return (invoke "main") (i32.const 10))

(module
(type $ft0 (func))
(type $ct0 (cont $ft0))

(type $ft1 (func (param (ref $ct0))))
(type $ct1 (cont $ft1))

(tag $t)

(func $f
(cont.new $ct1 (ref.func $g))
(switch $ct1 $t)
)
(elem declare func $f)

(func $g (param (ref $ct0)))
(elem declare func $g)

(func $entry
(cont.new $ct0 (ref.func $f))
(resume $ct0 (on $t switch))
)
)

(assert_invalid
(module
(rec
(type $ft (func (param (ref $ct))))
(type $ct (cont $ft)))
(tag $t (param i32))

(func (param $k (ref $ct))
(switch $ct $t)))
"type mismatch in switch tag")