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

Test array.new_data and array.new_elem with dropped segments #1849

Merged
merged 2 commits into from
Dec 2, 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
28 changes: 28 additions & 0 deletions test/core/gc/array.wast
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@
(array.new_data $vec $d (i32.const 1) (i32.const 3))
)

(func $new-overflow (export "new-overflow") (result (ref $vec))
(array.new_data $vec $d (i32.const 0x8000_0000) (i32.const 0x8000_0000))
)

(func $get_u (param $i i32) (param $v (ref $vec)) (result i32)
(array.get_u $vec (local.get $v) (local.get $i))
)
Expand Down Expand Up @@ -189,6 +193,10 @@
(func (export "len") (result i32)
(call $len (call $new))
)

(func (export "drop_segs")
(data.drop $d)
)
)

(assert_return (invoke "new") (ref.array))
Expand All @@ -198,10 +206,16 @@
(assert_return (invoke "set_get" (i32.const 1) (i32.const 7)) (i32.const 7))
(assert_return (invoke "len") (i32.const 3))

(assert_trap (invoke "new-overflow") "out of bounds memory access")
(assert_trap (invoke "get_u" (i32.const 10)) "out of bounds array access")
(assert_trap (invoke "get_s" (i32.const 10)) "out of bounds array access")
(assert_trap (invoke "set_get" (i32.const 10) (i32.const 7)) "out of bounds array access")

(assert_return (invoke "drop_segs"))

(assert_trap (invoke "new") "out of bounds memory access")
(assert_trap (invoke "new-overflow") "out of bounds memory access")

(module
(type $bvec (array i8))
(type $vec (array (ref $bvec)))
Expand All @@ -218,6 +232,10 @@
(array.new_elem $vec $e (i32.const 0) (i32.const 2))
)

(func $new-overflow (export "new-overflow") (result (ref $vec))
(array.new_elem $vec $e (i32.const 0x8000_0000) (i32.const 0x8000_0000))
)

(func $sub1 (result (ref $nvec))
(array.new_elem $nvec $e (i32.const 0) (i32.const 2))
)
Expand Down Expand Up @@ -249,6 +267,10 @@
(func (export "len") (result i32)
(call $len (call $new))
)

(func (export "drop_segs")
(elem.drop $e)
)
)

(assert_return (invoke "new") (ref.array))
Expand All @@ -258,9 +280,15 @@
(assert_return (invoke "set_get" (i32.const 0) (i32.const 1) (i32.const 1)) (i32.const 2))
(assert_return (invoke "len") (i32.const 2))

(assert_trap (invoke "new-overflow") "out of bounds table access")
(assert_trap (invoke "get" (i32.const 10) (i32.const 0)) "out of bounds array access")
(assert_trap (invoke "set_get" (i32.const 10) (i32.const 0) (i32.const 0)) "out of bounds array access")

(assert_return (invoke "drop_segs"))

(assert_trap (invoke "new") "out of bounds table access")
(assert_trap (invoke "new-overflow") "out of bounds table access")

(assert_invalid
(module
(type $a (array i64))
Expand Down