github.com/wasilibs/wazerox@v0.0.0-20240124024944-4923be63ab5f/internal/integration_test/spectest/v1/testdata/local_set.wast (about) 1 ;; Test `local.set` operator 2 3 (module 4 ;; Typing 5 6 (func (export "type-local-i32") (local i32) (local.set 0 (i32.const 0))) 7 (func (export "type-local-i64") (local i64) (local.set 0 (i64.const 0))) 8 (func (export "type-local-f32") (local f32) (local.set 0 (f32.const 0))) 9 (func (export "type-local-f64") (local f64) (local.set 0 (f64.const 0))) 10 11 (func (export "type-param-i32") (param i32) (local.set 0 (i32.const 10))) 12 (func (export "type-param-i64") (param i64) (local.set 0 (i64.const 11))) 13 (func (export "type-param-f32") (param f32) (local.set 0 (f32.const 11.1))) 14 (func (export "type-param-f64") (param f64) (local.set 0 (f64.const 12.2))) 15 16 (func (export "type-mixed") (param i64 f32 f64 i32 i32) (local f32 i64 i64 f64) 17 (local.set 0 (i64.const 0)) 18 (local.set 1 (f32.const 0)) 19 (local.set 2 (f64.const 0)) 20 (local.set 3 (i32.const 0)) 21 (local.set 4 (i32.const 0)) 22 (local.set 5 (f32.const 0)) 23 (local.set 6 (i64.const 0)) 24 (local.set 7 (i64.const 0)) 25 (local.set 8 (f64.const 0)) 26 ) 27 28 ;; Writing 29 30 (func (export "write") (param i64 f32 f64 i32 i32) (result i64) 31 (local f32 i64 i64 f64) 32 (local.set 1 (f32.const -0.3)) 33 (local.set 3 (i32.const 40)) 34 (local.set 4 (i32.const -7)) 35 (local.set 5 (f32.const 5.5)) 36 (local.set 6 (i64.const 6)) 37 (local.set 8 (f64.const 8)) 38 (i64.trunc_f64_s 39 (f64.add 40 (f64.convert_i64_u (local.get 0)) 41 (f64.add 42 (f64.promote_f32 (local.get 1)) 43 (f64.add 44 (local.get 2) 45 (f64.add 46 (f64.convert_i32_u (local.get 3)) 47 (f64.add 48 (f64.convert_i32_s (local.get 4)) 49 (f64.add 50 (f64.promote_f32 (local.get 5)) 51 (f64.add 52 (f64.convert_i64_u (local.get 6)) 53 (f64.add 54 (f64.convert_i64_u (local.get 7)) 55 (local.get 8) 56 ) 57 ) 58 ) 59 ) 60 ) 61 ) 62 ) 63 ) 64 ) 65 ) 66 67 ;; As parameter of control constructs and instructions 68 69 (func (export "as-block-value") (param i32) 70 (block (local.set 0 (i32.const 1))) 71 ) 72 (func (export "as-loop-value") (param i32) 73 (loop (local.set 0 (i32.const 3))) 74 ) 75 76 (func (export "as-br-value") (param i32) 77 (block (br 0 (local.set 0 (i32.const 9)))) 78 ) 79 (func (export "as-br_if-value") (param i32) 80 (block 81 (br_if 0 (local.set 0 (i32.const 8)) (i32.const 1)) 82 ) 83 ) 84 (func (export "as-br_if-value-cond") (param i32) 85 (block 86 (br_if 0 (i32.const 6) (local.set 0 (i32.const 9))) 87 ) 88 ) 89 (func (export "as-br_table-value") (param i32) 90 (block 91 (br_table 0 (local.set 0 (i32.const 10)) (i32.const 1)) 92 ) 93 ) 94 95 (func (export "as-return-value") (param i32) 96 (return (local.set 0 (i32.const 7))) 97 ) 98 99 (func (export "as-if-then") (param i32) 100 (if (local.get 0) (then (local.set 0 (i32.const 3)))) 101 ) 102 (func (export "as-if-else") (param i32) 103 (if (local.get 0) (then) (else (local.set 0 (i32.const 1)))) 104 ) 105 ) 106 107 (assert_return (invoke "type-local-i32")) 108 (assert_return (invoke "type-local-i64")) 109 (assert_return (invoke "type-local-f32")) 110 (assert_return (invoke "type-local-f64")) 111 112 (assert_return (invoke "type-param-i32" (i32.const 2))) 113 (assert_return (invoke "type-param-i64" (i64.const 3))) 114 (assert_return (invoke "type-param-f32" (f32.const 4.4))) 115 (assert_return (invoke "type-param-f64" (f64.const 5.5))) 116 117 (assert_return (invoke "as-block-value" (i32.const 0))) 118 (assert_return (invoke "as-loop-value" (i32.const 0))) 119 120 (assert_return (invoke "as-br-value" (i32.const 0))) 121 (assert_return (invoke "as-br_if-value" (i32.const 0))) 122 (assert_return (invoke "as-br_if-value-cond" (i32.const 0))) 123 (assert_return (invoke "as-br_table-value" (i32.const 0))) 124 125 (assert_return (invoke "as-return-value" (i32.const 0))) 126 127 (assert_return (invoke "as-if-then" (i32.const 1))) 128 (assert_return (invoke "as-if-else" (i32.const 0))) 129 130 (assert_return 131 (invoke "type-mixed" 132 (i64.const 1) (f32.const 2.2) (f64.const 3.3) (i32.const 4) (i32.const 5) 133 ) 134 ) 135 136 (assert_return 137 (invoke "write" 138 (i64.const 1) (f32.const 2) (f64.const 3.3) (i32.const 4) (i32.const 5) 139 ) 140 (i64.const 56) 141 ) 142 143 144 ;; Invalid typing of access to locals 145 146 147 (assert_invalid 148 (module (func $type-local-arg-void-vs-num (local i32) (local.set 0 (nop)))) 149 "type mismatch" 150 ) 151 (assert_invalid 152 (module (func $type-local-arg-num-vs-num (local i32) (local.set 0 (f32.const 0)))) 153 "type mismatch" 154 ) 155 (assert_invalid 156 (module (func $type-local-arg-num-vs-num (local f32) (local.set 0 (f64.const 0)))) 157 "type mismatch" 158 ) 159 (assert_invalid 160 (module (func $type-local-arg-num-vs-num (local f64 i64) (local.set 1 (f64.const 0)))) 161 "type mismatch" 162 ) 163 164 165 ;; Invalid typing of access to parameters 166 167 168 (assert_invalid 169 (module (func $type-param-arg-void-vs-num (param i32) (local.set 0 (nop)))) 170 "type mismatch" 171 ) 172 (assert_invalid 173 (module (func $type-param-arg-num-vs-num (param i32) (local.set 0 (f32.const 0)))) 174 "type mismatch" 175 ) 176 (assert_invalid 177 (module (func $type-param-arg-num-vs-num (param f32) (local.set 0 (f64.const 0)))) 178 "type mismatch" 179 ) 180 (assert_invalid 181 (module (func $type-param-arg-num-vs-num (param f64 i64) (local.set 1 (f64.const 0)))) 182 "type mismatch" 183 ) 184 185 (assert_invalid 186 (module 187 (func $type-param-arg-empty-vs-num (param i32) 188 (local.set 0) 189 ) 190 ) 191 "type mismatch" 192 ) 193 (assert_invalid 194 (module 195 (func $type-param-arg-empty-vs-num-in-block (param i32) 196 (i32.const 0) 197 (block (local.set 0)) 198 ) 199 ) 200 "type mismatch" 201 ) 202 (assert_invalid 203 (module 204 (func $type-param-arg-empty-vs-num-in-loop (param i32) 205 (i32.const 0) 206 (loop (local.set 0)) 207 ) 208 ) 209 "type mismatch" 210 ) 211 (assert_invalid 212 (module 213 (func $type-param-arg-empty-vs-num-in-then (param i32) 214 (i32.const 0) 215 (if (i32.const 1) (then (local.set 0))) 216 ) 217 ) 218 "type mismatch" 219 ) 220 (assert_invalid 221 (module 222 (func $type-param-arg-empty-vs-num-in-else (param i32) 223 (i32.const 0) 224 (if (result i32) (i32.const 0) (then (i32.const 0)) (else (local.set 0))) 225 ) 226 ) 227 "type mismatch" 228 ) 229 (assert_invalid 230 (module 231 (func $type-param-arg-empty-vs-num-in-br (param i32) 232 (i32.const 0) 233 (block (br 0 (local.set 0))) 234 ) 235 ) 236 "type mismatch" 237 ) 238 (assert_invalid 239 (module 240 (func $type-param-arg-empty-vs-num-in-br_if (param i32) 241 (i32.const 0) 242 (block (br_if 0 (local.set 0))) 243 ) 244 ) 245 "type mismatch" 246 ) 247 (assert_invalid 248 (module 249 (func $type-param-arg-empty-vs-num-in-br_table (param i32) 250 (i32.const 0) 251 (block (br_table 0 (local.set 0))) 252 ) 253 ) 254 "type mismatch" 255 ) 256 (assert_invalid 257 (module 258 (func $type-param-arg-empty-vs-num-in-return (param i32) 259 (return (local.set 0)) 260 ) 261 ) 262 "type mismatch" 263 ) 264 (assert_invalid 265 (module 266 (func $type-param-arg-empty-vs-num-in-select (param i32) 267 (select (local.set 0) (i32.const 1) (i32.const 2)) 268 ) 269 ) 270 "type mismatch" 271 ) 272 (assert_invalid 273 (module 274 (func $type-param-arg-empty-vs-num-in-call (param i32) 275 (call 1 (local.set 0)) 276 ) 277 (func (param i32) (result i32) (local.get 0)) 278 ) 279 "type mismatch" 280 ) 281 (assert_invalid 282 (module 283 (func $f (param i32) (result i32) (local.get 0)) 284 (type $sig (func (param i32) (result i32))) 285 (table funcref (elem $f)) 286 (func $type-param-arg-empty-vs-num-in-call_indirect (param i32) 287 (block (result i32) 288 (call_indirect (type $sig) 289 (local.set 0) (i32.const 0) 290 ) 291 ) 292 ) 293 ) 294 "type mismatch" 295 ) 296 297 298 ;; Invalid typing of access to mixed args 299 300 (assert_invalid 301 (module (func $type-mixed-arg-num-vs-num (param f32) (local i32) (local.set 1 (f32.const 0)))) 302 "type mismatch" 303 ) 304 (assert_invalid 305 (module (func $type-mixed-arg-num-vs-num (param i64 i32) (local f32) (local.set 1 (f32.const 0)))) 306 "type mismatch" 307 ) 308 (assert_invalid 309 (module (func $type-mixed-arg-num-vs-num (param i64) (local f64 i64) (local.set 1 (i64.const 0)))) 310 "type mismatch" 311 ) 312 313 314 ;; local.set should have no retval 315 316 (assert_invalid 317 (module (func $type-empty-vs-i32 (param i32) (result i32) (local.set 0 (i32.const 1)))) 318 "type mismatch" 319 ) 320 (assert_invalid 321 (module (func $type-empty-vs-i64 (param i64) (result i64) (local.set 0 (i64.const 1)))) 322 "type mismatch" 323 ) 324 (assert_invalid 325 (module (func $type-empty-vs-f32 (param f32) (result f32) (local.set 0 (f32.const 1)))) 326 "type mismatch" 327 ) 328 (assert_invalid 329 (module (func $type-empty-vs-f64 (param f64) (result f64) (local.set 0 (f64.const 1)))) 330 "type mismatch" 331 ) 332 333 334 ;; Invalid local index 335 336 (assert_invalid 337 (module (func $unbound-local (local i32 i64) (local.set 3 (i32.const 0)))) 338 "unknown local" 339 ) 340 (assert_invalid 341 (module (func $large-local (local i32 i64) (local.set 14324343 (i32.const 0)))) 342 "unknown local" 343 ) 344 345 (assert_invalid 346 (module (func $unbound-param (param i32 i64) (local.set 2 (i32.const 0)))) 347 "unknown local" 348 ) 349 (assert_invalid 350 (module (func $large-param (param i32 i64) (local.set 714324343 (i32.const 0)))) 351 "unknown local" 352 ) 353 354 (assert_invalid 355 (module (func $unbound-mixed (param i32) (local i32 i64) (local.set 3 (i32.const 0)))) 356 "unknown local" 357 ) 358 (assert_invalid 359 (module (func $large-mixed (param i64) (local i32 i64) (local.set 214324343 (i32.const 0)))) 360 "unknown local" 361 ) 362