Skip to content

Commit

Permalink
Factor local init tests to local_init.wast; add more (WebAssembly#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
titzer authored Nov 10, 2022
1 parent c27d6c7 commit 7642173
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 40 deletions.
40 changes: 0 additions & 40 deletions test/core/local_get.wast
Original file line number Diff line number Diff line change
Expand Up @@ -223,43 +223,3 @@
(module (func $large-mixed (param i64) (local i32 i64) (local.get 214324343) drop))
"unknown local"
)


;; Uninitialized undefaulted locals

(module
(func (export "get-after-set") (param $p (ref extern)) (result (ref extern))
(local $x (ref extern))
(local.set $x (local.get $p))
(local.get $x)
)
(func (export "get-after-tee") (param $p (ref extern)) (result (ref extern))
(local $x (ref extern))
(drop (local.tee $x (local.get $p)))
(local.get $x)
)
(func (export "get-in-block-after-set") (param $p (ref extern)) (result (ref extern))
(local $x (ref extern))
(local.set $x (local.get $p))
(block (result (ref extern)) (local.get $x))
)
)

(assert_return (invoke "get-after-set" (ref.extern 1)) (ref.extern 1))
(assert_return (invoke "get-after-tee" (ref.extern 2)) (ref.extern 2))
(assert_return (invoke "get-in-block-after-set" (ref.extern 3)) (ref.extern 3))

(assert_invalid
(module (func $uninit (local $x (ref extern)) (drop (local.get $x))))
"uninitialized local"
)
(assert_invalid
(module
(func $uninit-after-end (param $p (ref extern))
(local $x (ref extern))
(block (local.set $x (local.get $p)) (drop (local.tee $x (local.get $p))))
(drop (local.get $x))
)
)
"uninitialized local"
)
74 changes: 74 additions & 0 deletions test/core/local_init.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
;; Uninitialized undefaulted locals

(module
(func (export "get-after-set") (param $p (ref extern)) (result (ref extern))
(local $x (ref extern))
(local.set $x (local.get $p))
(local.get $x)
)
(func (export "get-after-tee") (param $p (ref extern)) (result (ref extern))
(local $x (ref extern))
(drop (local.tee $x (local.get $p)))
(local.get $x)
)
(func (export "get-in-block-after-set") (param $p (ref extern)) (result (ref extern))
(local $x (ref extern))
(local.set $x (local.get $p))
(block (result (ref extern)) (local.get $x))
)
)

(assert_return (invoke "get-after-set" (ref.extern 1)) (ref.extern 1))
(assert_return (invoke "get-after-tee" (ref.extern 2)) (ref.extern 2))
(assert_return (invoke "get-in-block-after-set" (ref.extern 3)) (ref.extern 3))

(assert_invalid
(module (func $uninit (local $x (ref extern)) (drop (local.get $x))))
"uninitialized local"
)
(assert_invalid
(module
(func $uninit-after-end (param $p (ref extern))
(local $x (ref extern))
(block (local.set $x (local.get $p)) (drop (local.tee $x (local.get $p))))
(drop (local.get $x))
)
)
"uninitialized local"
)
(assert_invalid
(module
(func $uninit-in-else (param $p (ref extern))
(local $x (ref extern))
(if (i32.const 0)
(then (local.set $x (local.get $p)))
(else (local.get $x))
)
)
)
"uninitialized local"
)

(assert_invalid
(module
(func $uninit-from-if (param $p (ref extern))
(local $x (ref extern))
(if (i32.const 0)
(then (local.set $x (local.get $p)))
(else (local.set $x (local.get $p)))
)
(drop (local.get $x))
)
)
"uninitialized local"
)

(module
(func (export "tee-init") (param $p (ref extern)) (result (ref extern))
(local $x (ref extern))
(drop (local.tee $x (local.get $p)))
(local.get $x)
)
)

(assert_return (invoke "tee-init" (ref.extern 1)) (ref.extern 1))

0 comments on commit 7642173

Please sign in to comment.