1;;! threads = true
2
3;; From https://bugzilla.mozilla.org/show_bug.cgi?id=1684861.
4;;
5
6(module
7  (type (;0;) (func))
8  (func $main (type 0)
9    i32.const -64
10    i32.const -63
11    memory.atomic.notify offset=1
12    unreachable)
13  (memory (;0;) 4 4)
14  (export "main" (func $main))
15)
16
17(assert_trap (invoke "main") "unaligned atomic")
18
19
20(module
21  (type (;0;) (func))
22  (func $main (type 0)
23    i32.const -64
24    i32.const -63
25    memory.atomic.notify offset=65536
26    unreachable)
27  (memory (;0;) 4 4)
28  (export "main" (func $main))
29)
30
31(assert_trap (invoke "main") "out of bounds memory access")
32
33
34(module
35  (type (;0;) (func))
36  (func $wait32 (type 0)
37    i32.const -64
38    i32.const 42
39    i64.const 0
40    memory.atomic.wait32 offset=1
41    unreachable)
42  (func $wait64 (type 0)
43    i32.const -64
44    i64.const 43
45    i64.const 0
46    memory.atomic.wait64 offset=3
47    unreachable)
48  (memory (;0;) 4 4)
49  (export "wait32" (func $wait32))
50  (export "wait64" (func $wait64))
51)
52
53(assert_trap (invoke "wait32") "unaligned atomic")
54(assert_trap (invoke "wait64") "unaligned atomic")
55
56(module
57  (type (;0;) (func))
58  (func $wait32 (type 0)
59    i32.const 0
60    i32.const 42
61    i64.const 0
62    memory.atomic.wait32
63    unreachable)
64  (func $wait64 (type 0)
65    i32.const 0
66    i64.const 43
67    i64.const 0
68    memory.atomic.wait64
69    unreachable)
70  (memory (;0;) 4 4)
71  (export "wait32" (func $wait32))
72  (export "wait64" (func $wait64))
73)
74
75(assert_trap (invoke "wait32") "atomic wait on non-shared memory")
76(assert_trap (invoke "wait64") "atomic wait on non-shared memory")
77
78;; not valid values for memory.atomic.wait
79(module
80  (memory 1 1 shared)
81  (type (;0;) (func))
82  (func $wait32 (result i32)
83    i32.const 0
84    i32.const 42
85    i64.const -1
86    memory.atomic.wait32
87    )
88  (func $wait64 (result i32)
89    i32.const 0
90    i64.const 43
91    i64.const -1
92    memory.atomic.wait64
93    )
94  (export "wait32" (func $wait32))
95  (export "wait64" (func $wait64))
96)
97
98(assert_return (invoke "wait32") (i32.const 1))
99(assert_return (invoke "wait64") (i32.const 1))
100
101;; timeout
102(module
103  (memory 1 1 shared)
104  (type (;0;) (func))
105  (func $wait32 (result i32)
106    i32.const 0
107    i32.const 0
108    i64.const 1000
109    memory.atomic.wait32
110    )
111  (func $wait64 (result i32)
112    i32.const 0
113    i64.const 0
114    i64.const 1000
115    memory.atomic.wait64
116    )
117  (export "wait32" (func $wait32))
118  (export "wait64" (func $wait64))
119)
120
121(assert_return (invoke "wait32") (i32.const 2))
122(assert_return (invoke "wait64") (i32.const 2))
123
124;; timeout on 0ns
125(module
126  (memory 1 1 shared)
127  (type (;0;) (func))
128  (func $wait32 (result i32)
129    i32.const 0
130    i32.const 0
131    i64.const 0
132    memory.atomic.wait32
133    )
134  (func $wait64 (result i32)
135    i32.const 0
136    i64.const 0
137    i64.const 0
138    memory.atomic.wait64
139    )
140  (export "wait32" (func $wait32))
141  (export "wait64" (func $wait64))
142)
143
144(assert_return (invoke "wait32") (i32.const 2))
145(assert_return (invoke "wait64") (i32.const 2))
146