| 1 |
;; RUN: wast --assert default --snapshot tests/snapshots % -f shared-everything-threads |
| 2 |
|
| 3 |
;; Check the `shared` attribute on globals. |
| 4 |
|
| 5 |
(module |
| 6 |
;; Imported. |
| 7 |
(global (import "spectest" "global_i32") (shared i32)) |
| 8 |
(global (import "spectest" "global_i32_mut") (shared mut i32)) |
| 9 |
(global (import "spectest" "global_i64") (shared i64)) |
| 10 |
(global (import "spectest" "global_i64_mut") (shared mut i64)) |
| 11 |
(global (import "spectest" "global_f32") (shared i32)) |
| 12 |
(global (import "spectest" "global_f32_mut") (shared mut f32)) |
| 13 |
(global (import "spectest" "global_f64") (shared f64)) |
| 14 |
(global (import "spectest" "global_f64_mut") (shared mut f64)) |
| 15 |
(global (import "spectest" "global_v128") (shared v128)) |
| 16 |
(global (import "spectest" "global_v128_mut") (shared mut v128)) |
| 17 |
|
| 18 |
;; Initialized. |
| 19 |
(global (shared i32) (i32.const 0)) |
| 20 |
(global (shared mut i32) (i32.const 0)) |
| 21 |
(global (shared i64) (i64.const 0)) |
| 22 |
(global (shared mut i64) (i64.const 0)) |
| 23 |
(global (shared f32) (f32.const 0)) |
| 24 |
(global (shared mut f32) (f32.const 0)) |
| 25 |
(global (shared f64) (f64.const 0)) |
| 26 |
(global (shared mut f64) (f64.const 0)) |
| 27 |
(global (shared v128) (v128.const i64x2 0 0)) |
| 28 |
(global (shared mut v128) (v128.const i64x2 0 0)) |
| 29 |
) |
| 30 |
|
| 31 |
(assert_malformed |
| 32 |
(module quote "(global (mut shared i64) (i64.const -1))") |
| 33 |
"unexpected token") |
| 34 |
|
| 35 |
(assert_invalid |
| 36 |
(module (global $a (import "spectest" "global_ref") (shared funcref))) |
| 37 |
"shared value type") |
| 38 |
|
| 39 |
;; Check global.atomic.get, global.atomic.set. |
| 40 |
(module |
| 41 |
(global $a (import "spectest" "global_i32") (shared i32)) |
| 42 |
(global $b (import "spectest" "global_i64") (shared mut i64)) |
| 43 |
(global $d (shared i32) (i32.const 0)) |
| 44 |
(global $e (shared mut i64) (i64.const 1)) |
| 45 |
|
| 46 |
(func (export "get-a-seqcst") (result i32) (global.atomic.get seq_cst $a)) |
| 47 |
(func (export "set-b-seqcst") (global.atomic.set seq_cst $b (i64.const 1))) |
| 48 |
(func (export "get-d-acqrel") (result i32) (global.atomic.get acq_rel $d)) |
| 49 |
(func (export "set-e-acqrel") (global.atomic.set acq_rel $e (i64.const 2))) |
| 50 |
) |
| 51 |
|
| 52 |
(assert_invalid |
| 53 |
(module |
| 54 |
(global $a (shared i32) (i32.const 0)) |
| 55 |
(func (export "set-shared") (global.atomic.set seq_cst $a (i32.const 1))) |
| 56 |
) |
| 57 |
"global is immutable") |
| 58 |
|
| 59 |
(assert_invalid |
| 60 |
(module |
| 61 |
(global $a (shared mut f32) (f32.const 0)) |
| 62 |
(func (result f32) (global.atomic.get seq_cst $a)) |
| 63 |
) |
| 64 |
"invalid type") |
| 65 |
|
| 66 |
(assert_invalid |
| 67 |
(module |
| 68 |
(global $a (shared mut f32) (f32.const 0)) |
| 69 |
(func (global.atomic.set seq_cst $a (f32.const 0))) |
| 70 |
) |
| 71 |
"invalid type") |
| 72 |
|
| 73 |
(assert_invalid |
| 74 |
(module |
| 75 |
(global $a (shared mut f32) (f32.const 0)) |
| 76 |
(func (result f32) (global.atomic.get acq_rel $a)) |
| 77 |
) |
| 78 |
"invalid type") |
| 79 |
|
| 80 |
(assert_invalid |
| 81 |
(module |
| 82 |
(global $a (shared mut f32) (f32.const 0)) |
| 83 |
(func (global.atomic.set acq_rel $a (f32.const 0))) |
| 84 |
) |
| 85 |
"invalid type") |
| 86 |
|
| 87 |
(assert_invalid |
| 88 |
(module |
| 89 |
(global $a (shared f32) (f32.const 0)) |
| 90 |
(func (result f32) (global.atomic.get seq_cst $a)) |
| 91 |
) |
| 92 |
"invalid type") |
| 93 |
|
| 94 |
(assert_invalid |
| 95 |
(module |
| 96 |
(global $a (shared f32) (f32.const 0)) |
| 97 |
(func (result f32) (global.atomic.get acq_rel $a)) |
| 98 |
) |
| 99 |
"invalid type") |
| 100 |
|
| 101 |
(assert_invalid |
| 102 |
(module |
| 103 |
(global $a (shared mut f64) (f64.const 0)) |
| 104 |
(func (result f64) (global.atomic.get seq_cst $a)) |
| 105 |
) |
| 106 |
"invalid type") |
| 107 |
|
| 108 |
(assert_invalid |
| 109 |
(module |
| 110 |
(global $a (shared mut f64) (f64.const 0)) |
| 111 |
(func (global.atomic.set seq_cst $a (f64.const 0))) |
| 112 |
) |
| 113 |
"invalid type") |
| 114 |
|
| 115 |
(assert_invalid |
| 116 |
(module |
| 117 |
(global $a (shared mut f64) (f64.const 0)) |
| 118 |
(func (result f64) (global.atomic.get acq_rel $a)) |
| 119 |
) |
| 120 |
"invalid type") |
| 121 |
|
| 122 |
(assert_invalid |
| 123 |
(module |
| 124 |
(global $a (shared mut f64) (f64.const 0)) |
| 125 |
(func (global.atomic.set acq_rel $a (f64.const 0))) |
| 126 |
) |
| 127 |
"invalid type") |
| 128 |
|
| 129 |
(assert_invalid |
| 130 |
(module |
| 131 |
(global $a (shared f64) (f64.const 0)) |
| 132 |
(func (result f64) (global.atomic.get seq_cst $a)) |
| 133 |
) |
| 134 |
"invalid type") |
| 135 |
|
| 136 |
(assert_invalid |
| 137 |
(module |
| 138 |
(global $a (shared f64) (f64.const 0)) |
| 139 |
(func (result f64) (global.atomic.get acq_rel $a)) |
| 140 |
) |
| 141 |
"invalid type") |
| 142 |
|
| 143 |
(assert_invalid |
| 144 |
(module |
| 145 |
(global $a (shared mut v128) (v128.const i64x2 0 0)) |
| 146 |
(func (result v128) (global.atomic.get seq_cst $a)) |
| 147 |
) |
| 148 |
"invalid type") |
| 149 |
|
| 150 |
(assert_invalid |
| 151 |
(module |
| 152 |
(global $a (shared mut v128) (v128.const i64x2 0 0)) |
| 153 |
(func (global.atomic.set seq_cst $a (v128.const i64x2 0 0))) |
| 154 |
) |
| 155 |
"invalid type") |
| 156 |
|
| 157 |
(assert_invalid |
| 158 |
(module |
| 159 |
(global $a (shared mut v128) (v128.const i64x2 0 0)) |
| 160 |
(func (result v128) (global.atomic.get acq_rel $a)) |
| 161 |
) |
| 162 |
"invalid type") |
| 163 |
|
| 164 |
(assert_invalid |
| 165 |
(module |
| 166 |
(global $a (shared mut v128) (v128.const i64x2 0 0)) |
| 167 |
(func (global.atomic.set acq_rel $a (v128.const i64x2 0 0))) |
| 168 |
) |
| 169 |
"invalid type") |
| 170 |
|
| 171 |
(assert_invalid |
| 172 |
(module |
| 173 |
(global $a (shared v128) (v128.const i64x2 0 0)) |
| 174 |
(func (result v128) (global.atomic.get seq_cst $a)) |
| 175 |
) |
| 176 |
"invalid type") |
| 177 |
|
| 178 |
(assert_invalid |
| 179 |
(module |
| 180 |
(global $a (shared v128) (v128.const i64x2 0 0)) |
| 181 |
(func (result v128) (global.atomic.get acq_rel $a)) |
| 182 |
) |
| 183 |
"invalid type") |
| 184 |
|
| 185 |
;; Check global.atomic.rmw.*. |
| 186 |
(module (;i32;) |
| 187 |
(global $a (import "spectest" "global_i32") (shared mut i32)) |
| 188 |
(global $b (shared mut i32) (i32.const 0)) |
| 189 |
(func (export "rmw-add-i32-seq_cst-$a") (param $x i32) (result i32) |
| 190 |
local.get $x |
| 191 |
global.atomic.rmw.add seq_cst $a) |
| 192 |
(func (export "rmw-add-i32-seq_cst-$b") (param $x i32) (result i32) |
| 193 |
local.get $x |
| 194 |
global.atomic.rmw.add seq_cst $b) |
| 195 |
(func (export "rmw-add-i32-acq_rel-$a") (param $x i32) (result i32) |
| 196 |
local.get $x |
| 197 |
global.atomic.rmw.add acq_rel $a) |
| 198 |
(func (export "rmw-add-i32-acq_rel-$b") (param $x i32) (result i32) |
| 199 |
local.get $x |
| 200 |
global.atomic.rmw.add acq_rel $b) |
| 201 |
(func (export "rmw-sub-i32-seq_cst-$a") (param $x i32) (result i32) |
| 202 |
local.get $x |
| 203 |
global.atomic.rmw.sub seq_cst $a) |
| 204 |
(func (export "rmw-sub-i32-seq_cst-$b") (param $x i32) (result i32) |
| 205 |
local.get $x |
| 206 |
global.atomic.rmw.sub seq_cst $b) |
| 207 |
(func (export "rmw-sub-i32-acq_rel-$a") (param $x i32) (result i32) |
| 208 |
local.get $x |
| 209 |
global.atomic.rmw.sub acq_rel $a) |
| 210 |
(func (export "rmw-sub-i32-acq_rel-$b") (param $x i32) (result i32) |
| 211 |
local.get $x |
| 212 |
global.atomic.rmw.sub acq_rel $b) |
| 213 |
(func (export "rmw-and-i32-seq_cst-$a") (param $x i32) (result i32) |
| 214 |
local.get $x |
| 215 |
global.atomic.rmw.and seq_cst $a) |
| 216 |
(func (export "rmw-and-i32-seq_cst-$b") (param $x i32) (result i32) |
| 217 |
local.get $x |
| 218 |
global.atomic.rmw.and seq_cst $b) |
| 219 |
(func (export "rmw-and-i32-acq_rel-$a") (param $x i32) (result i32) |
| 220 |
local.get $x |
| 221 |
global.atomic.rmw.and acq_rel $a) |
| 222 |
(func (export "rmw-and-i32-acq_rel-$b") (param $x i32) (result i32) |
| 223 |
local.get $x |
| 224 |
global.atomic.rmw.and acq_rel $b) |
| 225 |
(func (export "rmw-or-i32-seq_cst-$a") (param $x i32) (result i32) |
| 226 |
local.get $x |
| 227 |
global.atomic.rmw.or seq_cst $a) |
| 228 |
(func (export "rmw-or-i32-seq_cst-$b") (param $x i32) (result i32) |
| 229 |
local.get $x |
| 230 |
global.atomic.rmw.or seq_cst $b) |
| 231 |
(func (export "rmw-or-i32-acq_rel-$a") (param $x i32) (result i32) |
| 232 |
local.get $x |
| 233 |
global.atomic.rmw.or acq_rel $a) |
| 234 |
(func (export "rmw-or-i32-acq_rel-$b") (param $x i32) (result i32) |
| 235 |
local.get $x |
| 236 |
global.atomic.rmw.or acq_rel $b) |
| 237 |
(func (export "rmw-xor-i32-seq_cst-$a") (param $x i32) (result i32) |
| 238 |
local.get $x |
| 239 |
global.atomic.rmw.xor seq_cst $a) |
| 240 |
(func (export "rmw-xor-i32-seq_cst-$b") (param $x i32) (result i32) |
| 241 |
local.get $x |
| 242 |
global.atomic.rmw.xor seq_cst $b) |
| 243 |
(func (export "rmw-xor-i32-acq_rel-$a") (param $x i32) (result i32) |
| 244 |
local.get $x |
| 245 |
global.atomic.rmw.xor acq_rel $a) |
| 246 |
(func (export "rmw-xor-i32-acq_rel-$b") (param $x i32) (result i32) |
| 247 |
local.get $x |
| 248 |
global.atomic.rmw.xor acq_rel $b) |
| 249 |
(func (export "rmw-xchg-i32-seq_cst-$a") (param $x i32) (result i32) |
| 250 |
local.get $x |
| 251 |
global.atomic.rmw.xchg seq_cst $a) |
| 252 |
(func (export "rmw-xchg-i32-seq_cst-$b") (param $x i32) (result i32) |
| 253 |
local.get $x |
| 254 |
global.atomic.rmw.xchg seq_cst $b) |
| 255 |
(func (export "rmw-xchg-i32-acq_rel-$a") (param $x i32) (result i32) |
| 256 |
local.get $x |
| 257 |
global.atomic.rmw.xchg acq_rel $a) |
| 258 |
(func (export "rmw-xchg-i32-acq_rel-$b") (param $x i32) (result i32) |
| 259 |
local.get $x |
| 260 |
global.atomic.rmw.xchg acq_rel $b) |
| 261 |
(func (export "rmw-cmpxchg-i32-seq_cst-$a") (param $x i32) (param $y i32) (result i32) |
| 262 |
local.get $x |
| 263 |
local.get $y |
| 264 |
global.atomic.rmw.cmpxchg seq_cst $a) |
| 265 |
(func (export "rmw-cmpxchg-i32-seq_cst-$b") (param $x i32) (param $y i32) (result i32) |
| 266 |
local.get $x |
| 267 |
local.get $y |
| 268 |
global.atomic.rmw.cmpxchg seq_cst $b) |
| 269 |
(func (export "rmw-cmpxchg-i32-acq_rel-$a") (param $x i32) (param $y i32) (result i32) |
| 270 |
local.get $x |
| 271 |
local.get $y |
| 272 |
global.atomic.rmw.cmpxchg acq_rel $a) |
| 273 |
(func (export "rmw-cmpxchg-i32-acq_rel-$b") (param $x i32) (param $y i32) (result i32) |
| 274 |
local.get $x |
| 275 |
local.get $y |
| 276 |
global.atomic.rmw.cmpxchg acq_rel $b) |
| 277 |
) |
| 278 |
|
| 279 |
(module (;i64;) |
| 280 |
(global $a (import "spectest" "global_i64") (shared mut i64)) |
| 281 |
(global $b (shared mut i64) (i64.const 0)) |
| 282 |
(func (export "rmw-add-i64-seq_cst-$a") (param $x i64) (result i64) |
| 283 |
local.get $x |
| 284 |
global.atomic.rmw.add seq_cst $a) |
| 285 |
(func (export "rmw-add-i64-seq_cst-$b") (param $x i64) (result i64) |
| 286 |
local.get $x |
| 287 |
global.atomic.rmw.add seq_cst $b) |
| 288 |
(func (export "rmw-add-i64-acq_rel-$a") (param $x i64) (result i64) |
| 289 |
local.get $x |
| 290 |
global.atomic.rmw.add acq_rel $a) |
| 291 |
(func (export "rmw-add-i64-acq_rel-$b") (param $x i64) (result i64) |
| 292 |
local.get $x |
| 293 |
global.atomic.rmw.add acq_rel $b) |
| 294 |
(func (export "rmw-sub-i64-seq_cst-$a") (param $x i64) (result i64) |
| 295 |
local.get $x |
| 296 |
global.atomic.rmw.sub seq_cst $a) |
| 297 |
(func (export "rmw-sub-i64-seq_cst-$b") (param $x i64) (result i64) |
| 298 |
local.get $x |
| 299 |
global.atomic.rmw.sub seq_cst $b) |
| 300 |
(func (export "rmw-sub-i64-acq_rel-$a") (param $x i64) (result i64) |
| 301 |
local.get $x |
| 302 |
global.atomic.rmw.sub acq_rel $a) |
| 303 |
(func (export "rmw-sub-i64-acq_rel-$b") (param $x i64) (result i64) |
| 304 |
local.get $x |
| 305 |
global.atomic.rmw.sub acq_rel $b) |
| 306 |
(func (export "rmw-and-i64-seq_cst-$a") (param $x i64) (result i64) |
| 307 |
local.get $x |
| 308 |
global.atomic.rmw.and seq_cst $a) |
| 309 |
(func (export "rmw-and-i64-seq_cst-$b") (param $x i64) (result i64) |
| 310 |
local.get $x |
| 311 |
global.atomic.rmw.and seq_cst $b) |
| 312 |
(func (export "rmw-and-i64-acq_rel-$a") (param $x i64) (result i64) |
| 313 |
local.get $x |
| 314 |
global.atomic.rmw.and acq_rel $a) |
| 315 |
(func (export "rmw-and-i64-acq_rel-$b") (param $x i64) (result i64) |
| 316 |
local.get $x |
| 317 |
global.atomic.rmw.and acq_rel $b) |
| 318 |
(func (export "rmw-or-i64-seq_cst-$a") (param $x i64) (result i64) |
| 319 |
local.get $x |
| 320 |
global.atomic.rmw.or seq_cst $a) |
| 321 |
(func (export "rmw-or-i64-seq_cst-$b") (param $x i64) (result i64) |
| 322 |
local.get $x |
| 323 |
global.atomic.rmw.or seq_cst $b) |
| 324 |
(func (export "rmw-or-i64-acq_rel-$a") (param $x i64) (result i64) |
| 325 |
local.get $x |
| 326 |
global.atomic.rmw.or acq_rel $a) |
| 327 |
(func (export "rmw-or-i64-acq_rel-$b") (param $x i64) (result i64) |
| 328 |
local.get $x |
| 329 |
global.atomic.rmw.or acq_rel $b) |
| 330 |
(func (export "rmw-xor-i64-seq_cst-$a") (param $x i64) (result i64) |
| 331 |
local.get $x |
| 332 |
global.atomic.rmw.xor seq_cst $a) |
| 333 |
(func (export "rmw-xor-i64-seq_cst-$b") (param $x i64) (result i64) |
| 334 |
local.get $x |
| 335 |
global.atomic.rmw.xor seq_cst $b) |
| 336 |
(func (export "rmw-xor-i64-acq_rel-$a") (param $x i64) (result i64) |
| 337 |
local.get $x |
| 338 |
global.atomic.rmw.xor acq_rel $a) |
| 339 |
(func (export "rmw-xor-i64-acq_rel-$b") (param $x i64) (result i64) |
| 340 |
local.get $x |
| 341 |
global.atomic.rmw.xor acq_rel $b) |
| 342 |
(func (export "rmw-xchg-i64-seq_cst-$a") (param $x i64) (result i64) |
| 343 |
local.get $x |
| 344 |
global.atomic.rmw.xchg seq_cst $a) |
| 345 |
(func (export "rmw-xchg-i64-seq_cst-$b") (param $x i64) (result i64) |
| 346 |
local.get $x |
| 347 |
global.atomic.rmw.xchg seq_cst $b) |
| 348 |
(func (export "rmw-xchg-i64-acq_rel-$a") (param $x i64) (result i64) |
| 349 |
local.get $x |
| 350 |
global.atomic.rmw.xchg acq_rel $a) |
| 351 |
(func (export "rmw-xchg-i64-acq_rel-$b") (param $x i64) (result i64) |
| 352 |
local.get $x |
| 353 |
global.atomic.rmw.xchg acq_rel $b) |
| 354 |
(func (export "rmw-cmpxchg-i64-seq_cst-$a") (param $x i64) (param $y i64) (result i64) |
| 355 |
local.get $x |
| 356 |
local.get $y |
| 357 |
global.atomic.rmw.cmpxchg seq_cst $a) |
| 358 |
(func (export "rmw-cmpxchg-i64-seq_cst-$b") (param $x i64) (param $y i64) (result i64) |
| 359 |
local.get $x |
| 360 |
local.get $y |
| 361 |
global.atomic.rmw.cmpxchg seq_cst $b) |
| 362 |
(func (export "rmw-cmpxchg-i64-acq_rel-$a") (param $x i64) (param $y i64) (result i64) |
| 363 |
local.get $x |
| 364 |
local.get $y |
| 365 |
global.atomic.rmw.cmpxchg acq_rel $a) |
| 366 |
(func (export "rmw-cmpxchg-i64-acq_rel-$b") (param $x i64) (param $y i64) (result i64) |
| 367 |
local.get $x |
| 368 |
local.get $y |
| 369 |
global.atomic.rmw.cmpxchg acq_rel $b) |
| 370 |
) |
| 371 |
|
| 372 |
(assert_invalid |
| 373 |
(module |
| 374 |
(global $g (mut funcref) (ref.null func)) |
| 375 |
(func |
| 376 |
ref.null func |
| 377 |
global.atomic.rmw.xor acq_rel $g |
| 378 |
drop |
| 379 |
) |
| 380 |
) |
| 381 |
"invalid type: `global.atomic.rmw.*` only allows `i32` and `i64`") |
| 382 |
|
| 383 |
(assert_invalid |
| 384 |
(module |
| 385 |
(func |
| 386 |
global.atomic.rmw.xor acq_rel 200 |
| 387 |
) |
| 388 |
) |
| 389 |
"global index out of bounds") |
| 390 |
|
| 391 |
(assert_invalid |
| 392 |
(module |
| 393 |
(global $g (mut funcref) (ref.null func)) |
| 394 |
(func |
| 395 |
ref.null func |
| 396 |
global.atomic.rmw.xchg acq_rel $g |
| 397 |
drop |
| 398 |
) |
| 399 |
) |
| 400 |
"invalid type: `global.atomic.rmw.xchg` only allows `i32`, `i64` and subtypes of `anyref`") |
| 401 |
|
| 402 |
(module |
| 403 |
(global $g (mut eqref) (ref.null eq)) |
| 404 |
(func |
| 405 |
ref.null eq |
| 406 |
global.atomic.rmw.xchg acq_rel $g |
| 407 |
drop |
| 408 |
) |
| 409 |
) |
| 410 |
|
| 411 |
(assert_invalid |
| 412 |
(module |
| 413 |
(global $g (mut anyref) (ref.null any)) |
| 414 |
(func |
| 415 |
ref.null any |
| 416 |
ref.null any |
| 417 |
global.atomic.rmw.cmpxchg acq_rel $g |
| 418 |
drop |
| 419 |
) |
| 420 |
) |
| 421 |
"invalid type: `global.atomic.rmw.cmpxchg` only allows `i32`, `i64` and subtypes of `eqref`") |
| 422 |
|
| 423 |
(module |
| 424 |
(global $g (mut eqref) (ref.null eq)) |
| 425 |
(func |
| 426 |
ref.null eq |
| 427 |
ref.null eq |
| 428 |
global.atomic.rmw.cmpxchg acq_rel $g |
| 429 |
drop |
| 430 |
) |
| 431 |
) |