Fixed heap reference to memory. Added address spectest

This commit is contained in:
Syrus Akbary 2018-10-27 13:33:08 +02:00
parent 0e1dc88d9c
commit b94049f949
5 changed files with 3798 additions and 5 deletions

589
spectests/address.wast Normal file
View File

@ -0,0 +1,589 @@
;; Load i32 data with different offset/align arguments
(module
(memory 1)
(data (i32.const 0) "abcdefghijklmnopqrstuvwxyz")
(func (export "8u_good1") (param $i i32) (result i32)
(i32.load8_u offset=0 (get_local $i)) ;; 97 'a'
)
(func (export "8u_good2") (param $i i32) (result i32)
(i32.load8_u align=1 (get_local $i)) ;; 97 'a'
)
(func (export "8u_good3") (param $i i32) (result i32)
(i32.load8_u offset=1 align=1 (get_local $i)) ;; 98 'b'
)
(func (export "8u_good4") (param $i i32) (result i32)
(i32.load8_u offset=2 align=1 (get_local $i)) ;; 99 'c'
)
(func (export "8u_good5") (param $i i32) (result i32)
(i32.load8_u offset=25 align=1 (get_local $i)) ;; 122 'z'
)
(func (export "8s_good1") (param $i i32) (result i32)
(i32.load8_s offset=0 (get_local $i)) ;; 97 'a'
)
(func (export "8s_good2") (param $i i32) (result i32)
(i32.load8_s align=1 (get_local $i)) ;; 97 'a'
)
(func (export "8s_good3") (param $i i32) (result i32)
(i32.load8_s offset=1 align=1 (get_local $i)) ;; 98 'b'
)
(func (export "8s_good4") (param $i i32) (result i32)
(i32.load8_s offset=2 align=1 (get_local $i)) ;; 99 'c'
)
(func (export "8s_good5") (param $i i32) (result i32)
(i32.load8_s offset=25 align=1 (get_local $i)) ;; 122 'z'
)
(func (export "16u_good1") (param $i i32) (result i32)
(i32.load16_u offset=0 (get_local $i)) ;; 25185 'ab'
)
(func (export "16u_good2") (param $i i32) (result i32)
(i32.load16_u align=1 (get_local $i)) ;; 25185 'ab'
)
(func (export "16u_good3") (param $i i32) (result i32)
(i32.load16_u offset=1 align=1 (get_local $i)) ;; 25442 'bc'
)
(func (export "16u_good4") (param $i i32) (result i32)
(i32.load16_u offset=2 align=2 (get_local $i)) ;; 25699 'cd'
)
(func (export "16u_good5") (param $i i32) (result i32)
(i32.load16_u offset=25 align=2 (get_local $i)) ;; 122 'z\0'
)
(func (export "16s_good1") (param $i i32) (result i32)
(i32.load16_s offset=0 (get_local $i)) ;; 25185 'ab'
)
(func (export "16s_good2") (param $i i32) (result i32)
(i32.load16_s align=1 (get_local $i)) ;; 25185 'ab'
)
(func (export "16s_good3") (param $i i32) (result i32)
(i32.load16_s offset=1 align=1 (get_local $i)) ;; 25442 'bc'
)
(func (export "16s_good4") (param $i i32) (result i32)
(i32.load16_s offset=2 align=2 (get_local $i)) ;; 25699 'cd'
)
(func (export "16s_good5") (param $i i32) (result i32)
(i32.load16_s offset=25 align=2 (get_local $i)) ;; 122 'z\0'
)
(func (export "32_good1") (param $i i32) (result i32)
(i32.load offset=0 (get_local $i)) ;; 1684234849 'abcd'
)
(func (export "32_good2") (param $i i32) (result i32)
(i32.load align=1 (get_local $i)) ;; 1684234849 'abcd'
)
(func (export "32_good3") (param $i i32) (result i32)
(i32.load offset=1 align=1 (get_local $i)) ;; 1701077858 'bcde'
)
(func (export "32_good4") (param $i i32) (result i32)
(i32.load offset=2 align=2 (get_local $i)) ;; 1717920867 'cdef'
)
(func (export "32_good5") (param $i i32) (result i32)
(i32.load offset=25 align=4 (get_local $i)) ;; 122 'z\0\0\0'
)
(func (export "8u_bad") (param $i i32)
(drop (i32.load8_u offset=4294967295 (get_local $i)))
)
(func (export "8s_bad") (param $i i32)
(drop (i32.load8_s offset=4294967295 (get_local $i)))
)
(func (export "16u_bad") (param $i i32)
(drop (i32.load16_u offset=4294967295 (get_local $i)))
)
(func (export "16s_bad") (param $i i32)
(drop (i32.load16_s offset=4294967295 (get_local $i)))
)
(func (export "32_bad") (param $i i32)
(drop (i32.load offset=4294967295 (get_local $i)))
)
)
(assert_return (invoke "8u_good1" (i32.const 0)) (i32.const 97))
(assert_return (invoke "8u_good2" (i32.const 0)) (i32.const 97))
(assert_return (invoke "8u_good3" (i32.const 0)) (i32.const 98))
(assert_return (invoke "8u_good4" (i32.const 0)) (i32.const 99))
(assert_return (invoke "8u_good5" (i32.const 0)) (i32.const 122))
(assert_return (invoke "8s_good1" (i32.const 0)) (i32.const 97))
(assert_return (invoke "8s_good2" (i32.const 0)) (i32.const 97))
(assert_return (invoke "8s_good3" (i32.const 0)) (i32.const 98))
(assert_return (invoke "8s_good4" (i32.const 0)) (i32.const 99))
(assert_return (invoke "8s_good5" (i32.const 0)) (i32.const 122))
(assert_return (invoke "16u_good1" (i32.const 0)) (i32.const 25185))
(assert_return (invoke "16u_good2" (i32.const 0)) (i32.const 25185))
(assert_return (invoke "16u_good3" (i32.const 0)) (i32.const 25442))
(assert_return (invoke "16u_good4" (i32.const 0)) (i32.const 25699))
(assert_return (invoke "16u_good5" (i32.const 0)) (i32.const 122))
(assert_return (invoke "16s_good1" (i32.const 0)) (i32.const 25185))
(assert_return (invoke "16s_good2" (i32.const 0)) (i32.const 25185))
(assert_return (invoke "16s_good3" (i32.const 0)) (i32.const 25442))
(assert_return (invoke "16s_good4" (i32.const 0)) (i32.const 25699))
(assert_return (invoke "16s_good5" (i32.const 0)) (i32.const 122))
(assert_return (invoke "32_good1" (i32.const 0)) (i32.const 1684234849))
(assert_return (invoke "32_good2" (i32.const 0)) (i32.const 1684234849))
(assert_return (invoke "32_good3" (i32.const 0)) (i32.const 1701077858))
(assert_return (invoke "32_good4" (i32.const 0)) (i32.const 1717920867))
(assert_return (invoke "32_good5" (i32.const 0)) (i32.const 122))
(assert_return (invoke "8u_good1" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "8u_good2" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "8u_good3" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "8u_good4" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "8u_good5" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "8s_good1" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "8s_good2" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "8s_good3" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "8s_good4" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "8s_good5" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "16u_good1" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "16u_good2" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "16u_good3" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "16u_good4" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "16u_good5" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "16s_good1" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "16s_good2" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "16s_good3" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "16s_good4" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "16s_good5" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "32_good1" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "32_good2" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "32_good3" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "32_good4" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "32_good5" (i32.const 65507)) (i32.const 0))
(assert_return (invoke "8u_good1" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "8u_good2" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "8u_good3" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "8u_good4" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "8u_good5" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "8s_good1" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "8s_good2" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "8s_good3" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "8s_good4" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "8s_good5" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "16u_good1" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "16u_good2" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "16u_good3" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "16u_good4" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "16u_good5" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "16s_good1" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "16s_good2" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "16s_good3" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "16s_good4" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "16s_good5" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "32_good1" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "32_good2" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "32_good3" (i32.const 65508)) (i32.const 0))
(assert_return (invoke "32_good4" (i32.const 65508)) (i32.const 0))
(assert_trap (invoke "32_good5" (i32.const 65508)) "out of bounds memory access")
(assert_trap (invoke "8u_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "8s_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "16u_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "16s_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "32_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "8u_bad" (i32.const 1)) "out of bounds memory access")
(assert_trap (invoke "8s_bad" (i32.const 1)) "out of bounds memory access")
(assert_trap (invoke "16u_bad" (i32.const 1)) "out of bounds memory access")
(assert_trap (invoke "16s_bad" (i32.const 1)) "out of bounds memory access")
(assert_trap (invoke "32_bad" (i32.const 1)) "out of bounds memory access")
(assert_malformed
(module quote
"(memory 1)"
"(func (drop (i32.load offset=4294967296 (i32.const 0))))"
)
"i32 constant"
)
;; Load i64 data with different offset/align arguments
(module
(memory 1)
(data (i32.const 0) "abcdefghijklmnopqrstuvwxyz")
(func (export "8u_good1") (param $i i32) (result i64)
(i64.load8_u offset=0 (get_local $i)) ;; 97 'a'
)
(func (export "8u_good2") (param $i i32) (result i64)
(i64.load8_u align=1 (get_local $i)) ;; 97 'a'
)
(func (export "8u_good3") (param $i i32) (result i64)
(i64.load8_u offset=1 align=1 (get_local $i)) ;; 98 'b'
)
(func (export "8u_good4") (param $i i32) (result i64)
(i64.load8_u offset=2 align=1 (get_local $i)) ;; 99 'c'
)
(func (export "8u_good5") (param $i i32) (result i64)
(i64.load8_u offset=25 align=1 (get_local $i)) ;; 122 'z'
)
(func (export "8s_good1") (param $i i32) (result i64)
(i64.load8_s offset=0 (get_local $i)) ;; 97 'a'
)
(func (export "8s_good2") (param $i i32) (result i64)
(i64.load8_s align=1 (get_local $i)) ;; 97 'a'
)
(func (export "8s_good3") (param $i i32) (result i64)
(i64.load8_s offset=1 align=1 (get_local $i)) ;; 98 'b'
)
(func (export "8s_good4") (param $i i32) (result i64)
(i64.load8_s offset=2 align=1 (get_local $i)) ;; 99 'c'
)
(func (export "8s_good5") (param $i i32) (result i64)
(i64.load8_s offset=25 align=1 (get_local $i)) ;; 122 'z'
)
(func (export "16u_good1") (param $i i32) (result i64)
(i64.load16_u offset=0 (get_local $i)) ;; 25185 'ab'
)
(func (export "16u_good2") (param $i i32) (result i64)
(i64.load16_u align=1 (get_local $i)) ;; 25185 'ab'
)
(func (export "16u_good3") (param $i i32) (result i64)
(i64.load16_u offset=1 align=1 (get_local $i)) ;; 25442 'bc'
)
(func (export "16u_good4") (param $i i32) (result i64)
(i64.load16_u offset=2 align=2 (get_local $i)) ;; 25699 'cd'
)
(func (export "16u_good5") (param $i i32) (result i64)
(i64.load16_u offset=25 align=2 (get_local $i)) ;; 122 'z\0'
)
(func (export "16s_good1") (param $i i32) (result i64)
(i64.load16_s offset=0 (get_local $i)) ;; 25185 'ab'
)
(func (export "16s_good2") (param $i i32) (result i64)
(i64.load16_s align=1 (get_local $i)) ;; 25185 'ab'
)
(func (export "16s_good3") (param $i i32) (result i64)
(i64.load16_s offset=1 align=1 (get_local $i)) ;; 25442 'bc'
)
(func (export "16s_good4") (param $i i32) (result i64)
(i64.load16_s offset=2 align=2 (get_local $i)) ;; 25699 'cd'
)
(func (export "16s_good5") (param $i i32) (result i64)
(i64.load16_s offset=25 align=2 (get_local $i)) ;; 122 'z\0'
)
(func (export "32u_good1") (param $i i32) (result i64)
(i64.load32_u offset=0 (get_local $i)) ;; 1684234849 'abcd'
)
(func (export "32u_good2") (param $i i32) (result i64)
(i64.load32_u align=1 (get_local $i)) ;; 1684234849 'abcd'
)
(func (export "32u_good3") (param $i i32) (result i64)
(i64.load32_u offset=1 align=1 (get_local $i)) ;; 1701077858 'bcde'
)
(func (export "32u_good4") (param $i i32) (result i64)
(i64.load32_u offset=2 align=2 (get_local $i)) ;; 1717920867 'cdef'
)
(func (export "32u_good5") (param $i i32) (result i64)
(i64.load32_u offset=25 align=4 (get_local $i)) ;; 122 'z\0\0\0'
)
(func (export "32s_good1") (param $i i32) (result i64)
(i64.load32_s offset=0 (get_local $i)) ;; 1684234849 'abcd'
)
(func (export "32s_good2") (param $i i32) (result i64)
(i64.load32_s align=1 (get_local $i)) ;; 1684234849 'abcd'
)
(func (export "32s_good3") (param $i i32) (result i64)
(i64.load32_s offset=1 align=1 (get_local $i)) ;; 1701077858 'bcde'
)
(func (export "32s_good4") (param $i i32) (result i64)
(i64.load32_s offset=2 align=2 (get_local $i)) ;; 1717920867 'cdef'
)
(func (export "32s_good5") (param $i i32) (result i64)
(i64.load32_s offset=25 align=4 (get_local $i)) ;; 122 'z\0\0\0'
)
(func (export "64_good1") (param $i i32) (result i64)
(i64.load offset=0 (get_local $i)) ;; 0x6867666564636261 'abcdefgh'
)
(func (export "64_good2") (param $i i32) (result i64)
(i64.load align=1 (get_local $i)) ;; 0x6867666564636261 'abcdefgh'
)
(func (export "64_good3") (param $i i32) (result i64)
(i64.load offset=1 align=1 (get_local $i)) ;; 0x6968676665646362 'bcdefghi'
)
(func (export "64_good4") (param $i i32) (result i64)
(i64.load offset=2 align=2 (get_local $i)) ;; 0x6a69686766656463 'cdefghij'
)
(func (export "64_good5") (param $i i32) (result i64)
(i64.load offset=25 align=8 (get_local $i)) ;; 122 'z\0\0\0\0\0\0\0'
)
(func (export "8u_bad") (param $i i32)
(drop (i64.load8_u offset=4294967295 (get_local $i)))
)
(func (export "8s_bad") (param $i i32)
(drop (i64.load8_s offset=4294967295 (get_local $i)))
)
(func (export "16u_bad") (param $i i32)
(drop (i64.load16_u offset=4294967295 (get_local $i)))
)
(func (export "16s_bad") (param $i i32)
(drop (i64.load16_s offset=4294967295 (get_local $i)))
)
(func (export "32u_bad") (param $i i32)
(drop (i64.load32_u offset=4294967295 (get_local $i)))
)
(func (export "32s_bad") (param $i i32)
(drop (i64.load32_s offset=4294967295 (get_local $i)))
)
(func (export "64_bad") (param $i i32)
(drop (i64.load offset=4294967295 (get_local $i)))
)
)
(assert_return (invoke "8u_good1" (i32.const 0)) (i64.const 97))
(assert_return (invoke "8u_good2" (i32.const 0)) (i64.const 97))
(assert_return (invoke "8u_good3" (i32.const 0)) (i64.const 98))
(assert_return (invoke "8u_good4" (i32.const 0)) (i64.const 99))
(assert_return (invoke "8u_good5" (i32.const 0)) (i64.const 122))
(assert_return (invoke "8s_good1" (i32.const 0)) (i64.const 97))
(assert_return (invoke "8s_good2" (i32.const 0)) (i64.const 97))
(assert_return (invoke "8s_good3" (i32.const 0)) (i64.const 98))
(assert_return (invoke "8s_good4" (i32.const 0)) (i64.const 99))
(assert_return (invoke "8s_good5" (i32.const 0)) (i64.const 122))
(assert_return (invoke "16u_good1" (i32.const 0)) (i64.const 25185))
(assert_return (invoke "16u_good2" (i32.const 0)) (i64.const 25185))
(assert_return (invoke "16u_good3" (i32.const 0)) (i64.const 25442))
(assert_return (invoke "16u_good4" (i32.const 0)) (i64.const 25699))
(assert_return (invoke "16u_good5" (i32.const 0)) (i64.const 122))
(assert_return (invoke "16s_good1" (i32.const 0)) (i64.const 25185))
(assert_return (invoke "16s_good2" (i32.const 0)) (i64.const 25185))
(assert_return (invoke "16s_good3" (i32.const 0)) (i64.const 25442))
(assert_return (invoke "16s_good4" (i32.const 0)) (i64.const 25699))
(assert_return (invoke "16s_good5" (i32.const 0)) (i64.const 122))
(assert_return (invoke "32u_good1" (i32.const 0)) (i64.const 1684234849))
(assert_return (invoke "32u_good2" (i32.const 0)) (i64.const 1684234849))
(assert_return (invoke "32u_good3" (i32.const 0)) (i64.const 1701077858))
(assert_return (invoke "32u_good4" (i32.const 0)) (i64.const 1717920867))
(assert_return (invoke "32u_good5" (i32.const 0)) (i64.const 122))
(assert_return (invoke "32s_good1" (i32.const 0)) (i64.const 1684234849))
(assert_return (invoke "32s_good2" (i32.const 0)) (i64.const 1684234849))
(assert_return (invoke "32s_good3" (i32.const 0)) (i64.const 1701077858))
(assert_return (invoke "32s_good4" (i32.const 0)) (i64.const 1717920867))
(assert_return (invoke "32s_good5" (i32.const 0)) (i64.const 122))
(assert_return (invoke "64_good1" (i32.const 0)) (i64.const 0x6867666564636261))
(assert_return (invoke "64_good2" (i32.const 0)) (i64.const 0x6867666564636261))
(assert_return (invoke "64_good3" (i32.const 0)) (i64.const 0x6968676665646362))
(assert_return (invoke "64_good4" (i32.const 0)) (i64.const 0x6a69686766656463))
(assert_return (invoke "64_good5" (i32.const 0)) (i64.const 122))
(assert_return (invoke "8u_good1" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "8u_good2" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "8u_good3" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "8u_good4" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "8u_good5" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "8s_good1" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "8s_good2" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "8s_good3" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "8s_good4" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "8s_good5" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "16u_good1" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "16u_good2" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "16u_good3" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "16u_good4" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "16u_good5" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "16s_good1" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "16s_good2" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "16s_good3" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "16s_good4" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "16s_good5" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "32u_good1" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "32u_good2" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "32u_good3" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "32u_good4" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "32u_good5" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "32s_good1" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "32s_good2" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "32s_good3" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "32s_good4" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "32s_good5" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "64_good1" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "64_good2" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "64_good3" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "64_good4" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "64_good5" (i32.const 65503)) (i64.const 0))
(assert_return (invoke "8u_good1" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "8u_good2" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "8u_good3" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "8u_good4" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "8u_good5" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "8s_good1" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "8s_good2" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "8s_good3" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "8s_good4" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "8s_good5" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "16u_good1" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "16u_good2" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "16u_good3" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "16u_good4" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "16u_good5" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "16s_good1" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "16s_good2" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "16s_good3" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "16s_good4" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "16s_good5" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "32u_good1" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "32u_good2" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "32u_good3" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "32u_good4" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "32u_good5" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "32s_good1" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "32s_good2" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "32s_good3" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "32s_good4" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "32s_good5" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "64_good1" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "64_good2" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "64_good3" (i32.const 65504)) (i64.const 0))
(assert_return (invoke "64_good4" (i32.const 65504)) (i64.const 0))
(assert_trap (invoke "64_good5" (i32.const 65504)) "out of bounds memory access")
(assert_trap (invoke "8u_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "8s_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "16u_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "16s_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "32u_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "32s_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "64_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "8u_bad" (i32.const 1)) "out of bounds memory access")
(assert_trap (invoke "8s_bad" (i32.const 1)) "out of bounds memory access")
(assert_trap (invoke "16u_bad" (i32.const 1)) "out of bounds memory access")
(assert_trap (invoke "16s_bad" (i32.const 1)) "out of bounds memory access")
(assert_trap (invoke "32u_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "32s_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "64_bad" (i32.const 1)) "out of bounds memory access")
;; Load f32 data with different offset/align arguments
(module
(memory 1)
(data (i32.const 0) "\00\00\00\00\00\00\a0\7f\01\00\d0\7f")
(func (export "32_good1") (param $i i32) (result f32)
(f32.load offset=0 (get_local $i)) ;; 0.0 '\00\00\00\00'
)
(func (export "32_good2") (param $i i32) (result f32)
(f32.load align=1 (get_local $i)) ;; 0.0 '\00\00\00\00'
)
(func (export "32_good3") (param $i i32) (result f32)
(f32.load offset=1 align=1 (get_local $i)) ;; 0.0 '\00\00\00\00'
)
(func (export "32_good4") (param $i i32) (result f32)
(f32.load offset=2 align=2 (get_local $i)) ;; 0.0 '\00\00\00\00'
)
(func (export "32_good5") (param $i i32) (result f32)
(f32.load offset=8 align=4 (get_local $i)) ;; nan:0x500001 '\01\00\d0\7f'
)
(func (export "32_bad") (param $i i32)
(drop (f32.load offset=4294967295 (get_local $i)))
)
)
(assert_return (invoke "32_good1" (i32.const 0)) (f32.const 0.0))
(assert_return (invoke "32_good2" (i32.const 0)) (f32.const 0.0))
(assert_return (invoke "32_good3" (i32.const 0)) (f32.const 0.0))
(assert_return (invoke "32_good4" (i32.const 0)) (f32.const 0.0))
(assert_return (invoke "32_good5" (i32.const 0)) (f32.const nan:0x500001))
(assert_return (invoke "32_good1" (i32.const 65524)) (f32.const 0.0))
(assert_return (invoke "32_good2" (i32.const 65524)) (f32.const 0.0))
(assert_return (invoke "32_good3" (i32.const 65524)) (f32.const 0.0))
(assert_return (invoke "32_good4" (i32.const 65524)) (f32.const 0.0))
(assert_return (invoke "32_good5" (i32.const 65524)) (f32.const 0.0))
(assert_return (invoke "32_good1" (i32.const 65525)) (f32.const 0.0))
(assert_return (invoke "32_good2" (i32.const 65525)) (f32.const 0.0))
(assert_return (invoke "32_good3" (i32.const 65525)) (f32.const 0.0))
(assert_return (invoke "32_good4" (i32.const 65525)) (f32.const 0.0))
(assert_trap (invoke "32_good5" (i32.const 65525)) "out of bounds memory access")
(assert_trap (invoke "32_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "32_bad" (i32.const 1)) "out of bounds memory access")
;; Load f64 data with different offset/align arguments
(module
(memory 1)
(data (i32.const 0) "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\f4\7f\01\00\00\00\00\00\fc\7f")
(func (export "64_good1") (param $i i32) (result f64)
(f64.load offset=0 (get_local $i)) ;; 0.0 '\00\00\00\00\00\00\00\00'
)
(func (export "64_good2") (param $i i32) (result f64)
(f64.load align=1 (get_local $i)) ;; 0.0 '\00\00\00\00\00\00\00\00'
)
(func (export "64_good3") (param $i i32) (result f64)
(f64.load offset=1 align=1 (get_local $i)) ;; 0.0 '\00\00\00\00\00\00\00\00'
)
(func (export "64_good4") (param $i i32) (result f64)
(f64.load offset=2 align=2 (get_local $i)) ;; 0.0 '\00\00\00\00\00\00\00\00'
)
(func (export "64_good5") (param $i i32) (result f64)
(f64.load offset=18 align=8 (get_local $i)) ;; nan:0xc000000000001 '\01\00\00\00\00\00\fc\7f'
)
(func (export "64_bad") (param $i i32)
(drop (f64.load offset=4294967295 (get_local $i)))
)
)
(assert_return (invoke "64_good1" (i32.const 0)) (f64.const 0.0))
(assert_return (invoke "64_good2" (i32.const 0)) (f64.const 0.0))
(assert_return (invoke "64_good3" (i32.const 0)) (f64.const 0.0))
(assert_return (invoke "64_good4" (i32.const 0)) (f64.const 0.0))
(assert_return (invoke "64_good5" (i32.const 0)) (f64.const nan:0xc000000000001))
(assert_return (invoke "64_good1" (i32.const 65510)) (f64.const 0.0))
(assert_return (invoke "64_good2" (i32.const 65510)) (f64.const 0.0))
(assert_return (invoke "64_good3" (i32.const 65510)) (f64.const 0.0))
(assert_return (invoke "64_good4" (i32.const 65510)) (f64.const 0.0))
(assert_return (invoke "64_good5" (i32.const 65510)) (f64.const 0.0))
(assert_return (invoke "64_good1" (i32.const 65511)) (f64.const 0.0))
(assert_return (invoke "64_good2" (i32.const 65511)) (f64.const 0.0))
(assert_return (invoke "64_good3" (i32.const 65511)) (f64.const 0.0))
(assert_return (invoke "64_good4" (i32.const 65511)) (f64.const 0.0))
(assert_trap (invoke "64_good5" (i32.const 65511)) "out of bounds memory access")
(assert_trap (invoke "64_bad" (i32.const 0)) "out of bounds memory access")
(assert_trap (invoke "64_bad" (i32.const 1)) "out of bounds memory access")

View File

@ -15,7 +15,8 @@ static ENV_VAR: &str = "WASM_GENERATE_SPECTESTS";
static BANNER: &str = "// Rust test file autogenerated with cargo build (src/build_spectests.rs).
// Please do NOT modify it by hand, as it will be reseted on next build.\n";
const TESTS: [&str; 24] = [
const TESTS: [&str; 25] = [
"spectests/address.wast",
"spectests/align.wast",
"spectests/block.wast",
"spectests/br.wast",
@ -195,7 +196,10 @@ fn test_module_{}() {{
}}\n",
self.last_module,
// We do this to ident four spaces, so it looks aligned to the function body
wast_string.replace("\n", "\n ").replace("\"", "\\\""),
wast_string
.replace("\n", "\n ")
.replace("\\", "\\\\")
.replace("\"", "\\\""),
)
.as_str(),
);

3189
src/spectests/address.rs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3,6 +3,7 @@
// The _common module is not autogenerated, as it provides common functions for the spectests
mod _common;
mod address;
mod align;
mod block;
mod br;

View File

@ -344,18 +344,28 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> {
}
}
fn make_heap(&mut self, func: &mut ir::Function, _index: MemoryIndex) -> ir::Heap {
fn make_heap(&mut self, func: &mut ir::Function, index: MemoryIndex) -> ir::Heap {
// Create a static heap whose base address is stored at `vmctx+104`.
let vmctx = func.create_global_value(ir::GlobalValueData::VMContext);
let base = func.create_global_value(ir::GlobalValueData::Load {
let heap_base_addr = func.create_global_value(ir::GlobalValueData::Load {
base: vmctx,
offset: Offset32::new(104),
global_type: self.pointer_type(),
});
let pointer_bytes = self.pointer_bytes();
let memories_offset = (index * pointer_bytes as usize) as i32;
// We de-reference the vm_context.memories addr
let heap_base = func.create_global_value(ir::GlobalValueData::Load {
base: heap_base_addr,
offset: Offset32::new(memories_offset),
global_type: self.pointer_type(),
});
func.create_heap(ir::HeapData {
base: base,
base: heap_base,
min_size: Imm64::new(0),
guard_size: Imm64::new(LinearMemory::DEFAULT_GUARD_SIZE as i64),
style: ir::HeapStyle::Static {