Skip to content

Commit

Permalink
[simd] Add more address overflow tests
Browse files Browse the repository at this point in the history
Echo to github.com/WebAssembly/spec/pull/1188,
add more address overflow tests with offset set
to `1` and address set to `-1`, which may be complied
differently.
  • Loading branch information
Honry committed May 13, 2020
1 parent f434dee commit d64ca05
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Test/spec/simd/simd_address.wast
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
(v128.store offset=65520 align=1 (i32.const 0) (v128.const i32x4 0 1 2 3))
(v128.load offset=65520 (i32.const 0))
)
(func (export "store_data_6") (param $i i32)
(v128.store offset=1 align=1 (local.get $i) (v128.const i32x4 0 1 2 3))
)
)

(assert_return (invoke "load_data_1" (i32.const 0)) (v128.const i32x4 0x03020100 0x07060504 0x11100908 0x15141312))
Expand Down Expand Up @@ -83,6 +86,7 @@
(assert_return (invoke "load_data_4" (i32.const 65505)) (v128.const i8x16 0x18 0x19 0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 0x28 0x29 0x30 0x31 0x00 0x00))
(assert_return (invoke "load_data_5" (i32.const 65505)) (v128.const i8x16 0x31 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00))

(assert_trap (invoke "load_data_3" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "load_data_5" (i32.const 65506)) "out of bounds memory access")

(assert_return (invoke "store_data_0") (v128.const f32x4 0 1 2 3))
Expand All @@ -92,6 +96,8 @@
(assert_return (invoke "store_data_4") (v128.const i32x4 0 1 2 3))
(assert_return (invoke "store_data_5") (v128.const i32x4 0 1 2 3))

(assert_trap (invoke "store_data_6" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "store_data_6" (i32.const 65535)) "out of bounds memory access")

;; Load/Store v128 data with invalid offset

Expand Down
25 changes: 25 additions & 0 deletions Test/spec/simd/simd_load_extend.wast
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
(func (export "i16x8.load8x8_s_offset0_align1") (param $0 i32) (result v128)
(i16x8.load8x8_s offset=0 align=1 (local.get $0))
)
(func (export "i16x8.load8x8_s_offset1_align1") (param $0 i32) (result v128)
(i16x8.load8x8_s offset=1 align=1 (local.get $0))
)
(func (export "i16x8.load8x8_s_offset10_align4") (param $0 i32) (result v128)
(i16x8.load8x8_s offset=10 align=4 (local.get $0))
)
Expand All @@ -70,6 +73,9 @@
(func (export "i16x8.load8x8_u_offset0_align1") (param $0 i32) (result v128)
(i16x8.load8x8_u offset=0 align=1 (local.get $0))
)
(func (export "i16x8.load8x8_u_offset1_align1") (param $0 i32) (result v128)
(i16x8.load8x8_u offset=1 align=1 (local.get $0))
)
(func (export "i16x8.load8x8_u_offset10_align4") (param $0 i32) (result v128)
(i16x8.load8x8_u offset=10 align=4 (local.get $0))
)
Expand All @@ -86,6 +92,9 @@
(func (export "i32x4.load16x4_s_offset0_align1") (param $0 i32) (result v128)
(i32x4.load16x4_s offset=0 align=1 (local.get $0))
)
(func (export "i32x4.load16x4_s_offset1_align1") (param $0 i32) (result v128)
(i32x4.load16x4_s offset=1 align=1 (local.get $0))
)
(func (export "i32x4.load16x4_s_offset10_align4") (param $0 i32) (result v128)
(i32x4.load16x4_s offset=10 align=4 (local.get $0))
)
Expand All @@ -101,6 +110,9 @@
(func (export "i32x4.load16x4_u_offset0_align1") (param $0 i32) (result v128)
(i32x4.load16x4_u offset=0 align=1 (local.get $0))
)
(func (export "i32x4.load16x4_u_offset1_align1") (param $0 i32) (result v128)
(i32x4.load16x4_u offset=1 align=1 (local.get $0))
)
(func (export "i32x4.load16x4_u_offset10_align4") (param $0 i32) (result v128)
(i32x4.load16x4_u offset=10 align=4 (local.get $0))
)
Expand All @@ -117,6 +129,9 @@
(func (export "i64x2.load32x2_s_offset0_align1") (param $0 i32) (result v128)
(i64x2.load32x2_s offset=0 align=1 (local.get $0))
)
(func (export "i64x2.load32x2_s_offset1_align1") (param $0 i32) (result v128)
(i64x2.load32x2_s offset=1 align=1 (local.get $0))
)
(func (export "i64x2.load32x2_s_offset10_align4") (param $0 i32) (result v128)
(i64x2.load32x2_s offset=10 align=4 (local.get $0))
)
Expand All @@ -132,6 +147,9 @@
(func (export "i64x2.load32x2_u_offset0_align1") (param $0 i32) (result v128)
(i64x2.load32x2_u offset=0 align=1 (local.get $0))
)
(func (export "i64x2.load32x2_u_offset1_align1") (param $0 i32) (result v128)
(i64x2.load32x2_u offset=1 align=1 (local.get $0))
)
(func (export "i64x2.load32x2_u_offset10_align4") (param $0 i32) (result v128)
(i64x2.load32x2_u offset=10 align=4 (local.get $0))
)
Expand Down Expand Up @@ -212,6 +230,13 @@
(assert_trap (invoke "i64x2.load32x2_s" (i32.const 65529)) "out of bounds memory access")
(assert_trap (invoke "i64x2.load32x2_u" (i32.const 65529)) "out of bounds memory access")

(assert_trap (invoke "i16x8.load8x8_s_offset1_align1" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i16x8.load8x8_u_offset1_align1" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i32x4.load16x4_s_offset1_align1" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i32x4.load16x4_u_offset1_align1" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i64x2.load32x2_s_offset1_align1" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "i64x2.load32x2_u_offset1_align1" (i32.const -1)) "out of bounds memory access")

;; type check
(assert_invalid (module (memory 0) (func (result v128) (i16x8.load8x8_s (f32.const 0)))) "type mismatch")
(assert_invalid (module (memory 0) (func (result v128) (i16x8.load8x8_u (f32.const 0)))) "type mismatch")
Expand Down
5 changes: 5 additions & 0 deletions Test/spec/simd/simd_load_splat.wast
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@
(assert_trap (invoke "v64x2.offset2_align4" (i32.const 65528)) "out of bounds memory access")
(assert_trap (invoke "v64x2.offset15_align8" (i32.const 65528)) "out of bounds memory access")

(assert_trap (invoke "v8x16.offset1_align1" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "v16x8.offset1_align1" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "v32x4.offset1_align1" (i32.const -1)) "out of bounds memory access")
(assert_trap (invoke "v64x2.offset1_align2" (i32.const -1)) "out of bounds memory access")

(assert_trap (invoke "v8x16.offset65536" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "v16x8.offset65535" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "v32x4.offset65533" (i32.const 0)) "out of bounds memory access")
Expand Down

0 comments on commit d64ca05

Please sign in to comment.