From 7642173b706d7bfc0559c6445063fb1ffe865210 Mon Sep 17 00:00:00 2001 From: "Ben L. Titzer" Date: Thu, 10 Nov 2022 06:24:05 -0500 Subject: [PATCH] Factor local init tests to local_init.wast; add more (#84) --- test/core/local_get.wast | 40 --------------------- test/core/local_init.wast | 74 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 40 deletions(-) create mode 100644 test/core/local_init.wast diff --git a/test/core/local_get.wast b/test/core/local_get.wast index b56aeec30b..45dbcaeeb4 100644 --- a/test/core/local_get.wast +++ b/test/core/local_get.wast @@ -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" -) diff --git a/test/core/local_init.wast b/test/core/local_init.wast new file mode 100644 index 0000000000..176ccc64bb --- /dev/null +++ b/test/core/local_init.wast @@ -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))