github.com/tetratelabs/wazero@v1.7.3-0.20240513003603-48f702e154b5/internal/integration_test/spectest/v1/testdata/load.wast (about)

     1  ;; Load operator as the argument of control constructs and instructions
     2  
     3  (module
     4    (memory 1)
     5  
     6    (func (export "as-br-value") (result i32)
     7      (block (result i32) (br 0 (i32.load (i32.const 0))))
     8    )
     9  
    10    (func (export "as-br_if-cond")
    11      (block (br_if 0 (i32.load (i32.const 0))))
    12    )
    13    (func (export "as-br_if-value") (result i32)
    14      (block (result i32)
    15        (drop (br_if 0 (i32.load (i32.const 0)) (i32.const 1))) (i32.const 7)
    16      )
    17    )
    18    (func (export "as-br_if-value-cond") (result i32)
    19      (block (result i32)
    20        (drop (br_if 0 (i32.const 6) (i32.load (i32.const 0)))) (i32.const 7)
    21      )
    22    )
    23  
    24    (func (export "as-br_table-index")
    25      (block (br_table 0 0 0 (i32.load (i32.const 0))))
    26    )
    27    (func (export "as-br_table-value") (result i32)
    28      (block (result i32)
    29        (br_table 0 0 0 (i32.load (i32.const 0)) (i32.const 1)) (i32.const 7)
    30      )
    31    )
    32    (func (export "as-br_table-value-index") (result i32)
    33      (block (result i32)
    34        (br_table 0 0 (i32.const 6) (i32.load (i32.const 0))) (i32.const 7)
    35      )
    36    )
    37  
    38    (func (export "as-return-value") (result i32)
    39      (return (i32.load (i32.const 0)))
    40    )
    41  
    42    (func (export "as-if-cond") (result i32)
    43      (if (result i32) (i32.load (i32.const 0))
    44        (then (i32.const 0)) (else (i32.const 1))
    45      )
    46    )
    47    (func (export "as-if-then") (result i32)
    48      (if (result i32) (i32.const 1)
    49        (then (i32.load (i32.const 0))) (else (i32.const 0))
    50      )
    51    )
    52    (func (export "as-if-else") (result i32)
    53      (if (result i32) (i32.const 0)
    54        (then (i32.const 0)) (else (i32.load (i32.const 0)))
    55      )
    56    )
    57  
    58    (func (export "as-select-first") (param i32 i32) (result i32)
    59      (select (i32.load (i32.const 0)) (local.get 0) (local.get 1))
    60    )
    61    (func (export "as-select-second") (param i32 i32) (result i32)
    62      (select (local.get 0) (i32.load (i32.const 0)) (local.get 1))
    63    )
    64    (func (export "as-select-cond") (result i32)
    65      (select (i32.const 0) (i32.const 1) (i32.load (i32.const 0)))
    66    )
    67  
    68    (func $f (param i32 i32 i32) (result i32) (i32.const -1))
    69    (func (export "as-call-first") (result i32)
    70      (call $f (i32.load (i32.const 0)) (i32.const 2) (i32.const 3))
    71    )
    72    (func (export "as-call-mid") (result i32)
    73      (call $f (i32.const 1) (i32.load (i32.const 0)) (i32.const 3))
    74    )
    75    (func (export "as-call-last") (result i32)
    76      (call $f (i32.const 1) (i32.const 2) (i32.load (i32.const 0)))
    77    )
    78  
    79    (type $sig (func (param i32 i32 i32) (result i32)))
    80    (table funcref (elem $f))
    81    (func (export "as-call_indirect-first") (result i32)
    82      (call_indirect (type $sig)
    83        (i32.load (i32.const 0)) (i32.const 2) (i32.const 3) (i32.const 0)
    84      )
    85    )
    86    (func (export "as-call_indirect-mid") (result i32)
    87      (call_indirect (type $sig)
    88        (i32.const 1) (i32.load (i32.const 0)) (i32.const 3) (i32.const 0)
    89      )
    90    )
    91    (func (export "as-call_indirect-last") (result i32)
    92      (call_indirect (type $sig)
    93        (i32.const 1) (i32.const 2) (i32.load (i32.const 0)) (i32.const 0)
    94      )
    95    )
    96    (func (export "as-call_indirect-index") (result i32)
    97      (call_indirect (type $sig)
    98        (i32.const 1) (i32.const 2) (i32.const 3) (i32.load (i32.const 0))
    99      )
   100    )
   101  
   102    (func (export "as-local.set-value") (local i32)
   103      (local.set 0 (i32.load (i32.const 0)))
   104    )
   105    (func (export "as-local.tee-value") (result i32) (local i32)
   106      (local.tee 0 (i32.load (i32.const 0)))
   107    )
   108    (global $g (mut i32) (i32.const 0))
   109    (func (export "as-global.set-value") (local i32)
   110      (global.set $g (i32.load (i32.const 0)))
   111    )
   112  
   113    (func (export "as-load-address") (result i32)
   114      (i32.load (i32.load (i32.const 0)))
   115    )
   116    (func (export "as-loadN-address") (result i32)
   117      (i32.load8_s (i32.load (i32.const 0)))
   118    )
   119  
   120    (func (export "as-store-address")
   121      (i32.store (i32.load (i32.const 0)) (i32.const 7))
   122    )
   123    (func (export "as-store-value")
   124      (i32.store (i32.const 2) (i32.load (i32.const 0)))
   125    )
   126  
   127    (func (export "as-storeN-address")
   128      (i32.store8 (i32.load8_s (i32.const 0)) (i32.const 7))
   129    )
   130    (func (export "as-storeN-value")
   131      (i32.store16 (i32.const 2) (i32.load (i32.const 0)))
   132    )
   133  
   134    (func (export "as-unary-operand") (result i32)
   135      (i32.clz (i32.load (i32.const 100)))
   136    )
   137  
   138    (func (export "as-binary-left") (result i32)
   139      (i32.add (i32.load (i32.const 100)) (i32.const 10))
   140    )
   141    (func (export "as-binary-right") (result i32)
   142      (i32.sub (i32.const 10) (i32.load (i32.const 100)))
   143    )
   144  
   145    (func (export "as-test-operand") (result i32)
   146      (i32.eqz (i32.load (i32.const 100)))
   147    )
   148  
   149    (func (export "as-compare-left") (result i32)
   150      (i32.le_s (i32.load (i32.const 100)) (i32.const 10))
   151    )
   152    (func (export "as-compare-right") (result i32)
   153      (i32.ne (i32.const 10) (i32.load (i32.const 100)))
   154    )
   155  
   156    (func (export "as-memory.grow-size") (result i32)
   157      (memory.grow (i32.load (i32.const 100)))
   158    )
   159  )
   160  
   161  (assert_return (invoke "as-br-value") (i32.const 0))
   162  
   163  (assert_return (invoke "as-br_if-cond"))
   164  (assert_return (invoke "as-br_if-value") (i32.const 0))
   165  (assert_return (invoke "as-br_if-value-cond") (i32.const 7))
   166  
   167  (assert_return (invoke "as-br_table-index"))
   168  (assert_return (invoke "as-br_table-value") (i32.const 0))
   169  (assert_return (invoke "as-br_table-value-index") (i32.const 6))
   170  
   171  (assert_return (invoke "as-return-value") (i32.const 0))
   172  
   173  (assert_return (invoke "as-if-cond") (i32.const 1))
   174  (assert_return (invoke "as-if-then") (i32.const 0))
   175  (assert_return (invoke "as-if-else") (i32.const 0))
   176  
   177  (assert_return (invoke "as-select-first" (i32.const 0) (i32.const 1)) (i32.const 0))
   178  (assert_return (invoke "as-select-second" (i32.const 0) (i32.const 0)) (i32.const 0))
   179  (assert_return (invoke "as-select-cond") (i32.const 1))
   180  
   181  (assert_return (invoke "as-call-first") (i32.const -1))
   182  (assert_return (invoke "as-call-mid") (i32.const -1))
   183  (assert_return (invoke "as-call-last") (i32.const -1))
   184  
   185  (assert_return (invoke "as-call_indirect-first") (i32.const -1))
   186  (assert_return (invoke "as-call_indirect-mid") (i32.const -1))
   187  (assert_return (invoke "as-call_indirect-last") (i32.const -1))
   188  (assert_return (invoke "as-call_indirect-index") (i32.const -1))
   189  
   190  (assert_return (invoke "as-local.set-value"))
   191  (assert_return (invoke "as-local.tee-value") (i32.const 0))
   192  (assert_return (invoke "as-global.set-value"))
   193  
   194  (assert_return (invoke "as-load-address") (i32.const 0))
   195  (assert_return (invoke "as-loadN-address") (i32.const 0))
   196  (assert_return (invoke "as-store-address"))
   197  (assert_return (invoke "as-store-value"))
   198  (assert_return (invoke "as-storeN-address"))
   199  (assert_return (invoke "as-storeN-value"))
   200  
   201  (assert_return (invoke "as-unary-operand") (i32.const 32))
   202  
   203  (assert_return (invoke "as-binary-left") (i32.const 10))
   204  (assert_return (invoke "as-binary-right") (i32.const 10))
   205  
   206  (assert_return (invoke "as-test-operand") (i32.const 1))
   207  
   208  (assert_return (invoke "as-compare-left") (i32.const 1))
   209  (assert_return (invoke "as-compare-right") (i32.const 1))
   210  
   211  (assert_return (invoke "as-memory.grow-size") (i32.const 1))
   212  
   213  (assert_malformed
   214    (module quote
   215      "(memory 1)"
   216      "(func (param i32) (result i32) (i32.load32 (local.get 0)))"
   217    )
   218    "unknown operator"
   219  )
   220  (assert_malformed
   221    (module quote
   222      "(memory 1)"
   223      "(func (param i32) (result i32) (i32.load32_u (local.get 0)))"
   224    )
   225    "unknown operator"
   226  )
   227  (assert_malformed
   228    (module quote
   229      "(memory 1)"
   230      "(func (param i32) (result i32) (i32.load32_s (local.get 0)))"
   231    )
   232    "unknown operator"
   233  )
   234  (assert_malformed
   235    (module quote
   236      "(memory 1)"
   237      "(func (param i32) (result i32) (i32.load64 (local.get 0)))"
   238    )
   239    "unknown operator"
   240  )
   241  (assert_malformed
   242    (module quote
   243      "(memory 1)"
   244      "(func (param i32) (result i32) (i32.load64_u (local.get 0)))"
   245    )
   246    "unknown operator"
   247  )
   248  (assert_malformed
   249    (module quote
   250      "(memory 1)"
   251      "(func (param i32) (result i32) (i32.load64_s (local.get 0)))"
   252    )
   253    "unknown operator"
   254  )
   255  
   256  (assert_malformed
   257    (module quote
   258      "(memory 1)"
   259      "(func (param i32) (result i64) (i64.load64 (local.get 0)))"
   260    )
   261    "unknown operator"
   262  )
   263  (assert_malformed
   264    (module quote
   265      "(memory 1)"
   266      "(func (param i32) (result i64) (i64.load64_u (local.get 0)))"
   267    )
   268    "unknown operator"
   269  )
   270  (assert_malformed
   271    (module quote
   272      "(memory 1)"
   273      "(func (param i32) (result i64) (i64.load64_s (local.get 0)))"
   274    )
   275    "unknown operator"
   276  )
   277  
   278  (assert_malformed
   279    (module quote
   280      "(memory 1)"
   281      "(func (param i32) (result f32) (f32.load32 (local.get 0)))"
   282    )
   283    "unknown operator"
   284  )
   285  (assert_malformed
   286    (module quote
   287      "(memory 1)"
   288      "(func (param i32) (result f32) (f32.load64 (local.get 0)))"
   289    )
   290    "unknown operator"
   291  )
   292  
   293  (assert_malformed
   294    (module quote
   295      "(memory 1)"
   296      "(func (param i32) (result f64) (f64.load32 (local.get 0)))"
   297    )
   298    "unknown operator"
   299  )
   300  (assert_malformed
   301    (module quote
   302      "(memory 1)"
   303      "(func (param i32) (result f64) (f64.load64 (local.get 0)))"
   304    )
   305    "unknown operator"
   306  )
   307  
   308  
   309  ;; load should have retval
   310  
   311  (assert_invalid
   312    (module (memory 1) (func $load_i32 (i32.load (i32.const 0))))
   313    "type mismatch"
   314  )
   315  (assert_invalid
   316    (module (memory 1) (func $load8_s_i32 (i32.load8_s (i32.const 0))))
   317    "type mismatch"
   318  )
   319  (assert_invalid
   320    (module (memory 1) (func $load8_u_i32 (i32.load8_u (i32.const 0))))
   321    "type mismatch"
   322  )
   323  (assert_invalid
   324    (module (memory 1) (func $load16_s_i32 (i32.load16_s (i32.const 0))))
   325    "type mismatch"
   326  )
   327  (assert_invalid
   328    (module (memory 1) (func $load16_u_i32 (i32.load16_u (i32.const 0))))
   329    "type mismatch"
   330  )
   331  (assert_invalid
   332    (module (memory 1) (func $load_i64 (i64.load (i32.const 0))))
   333    "type mismatch"
   334  )
   335  (assert_invalid
   336    (module (memory 1) (func $load8_s_i64 (i64.load8_s (i32.const 0))))
   337    "type mismatch"
   338  )
   339  (assert_invalid
   340    (module (memory 1) (func $load8_u_i64 (i64.load8_u (i32.const 0))))
   341    "type mismatch"
   342  )
   343  (assert_invalid
   344    (module (memory 1) (func $load16_s_i64 (i64.load16_s (i32.const 0))))
   345    "type mismatch"
   346  )
   347  (assert_invalid
   348    (module (memory 1) (func $load16_u_i64 (i64.load16_u (i32.const 0))))
   349    "type mismatch"
   350  )
   351  (assert_invalid
   352    (module (memory 1) (func $load32_s_i64 (i64.load32_s (i32.const 0))))
   353    "type mismatch"
   354  )
   355  (assert_invalid
   356    (module (memory 1) (func $load32_u_i64 (i64.load32_u (i32.const 0))))
   357    "type mismatch"
   358  )
   359  (assert_invalid
   360    (module (memory 1) (func $load_f32 (f32.load (i32.const 0))))
   361    "type mismatch"
   362  )
   363  (assert_invalid
   364    (module (memory 1) (func $load_f64 (f64.load (i32.const 0))))
   365    "type mismatch"
   366  )
   367  
   368  
   369  ;; Type check
   370  
   371  (assert_invalid (module (memory 1) (func (result i32) (i32.load (f32.const 0)))) "type mismatch")
   372  (assert_invalid (module (memory 1) (func (result i32) (i32.load8_s (f32.const 0)))) "type mismatch")
   373  (assert_invalid (module (memory 1) (func (result i32) (i32.load8_u (f32.const 0)))) "type mismatch")
   374  (assert_invalid (module (memory 1) (func (result i32) (i32.load16_s (f32.const 0)))) "type mismatch")
   375  (assert_invalid (module (memory 1) (func (result i32) (i32.load16_u (f32.const 0)))) "type mismatch")
   376  (assert_invalid (module (memory 1) (func (result i64) (i64.load (f32.const 0)))) "type mismatch")
   377  (assert_invalid (module (memory 1) (func (result i64) (i64.load8_s (f32.const 0)))) "type mismatch")
   378  (assert_invalid (module (memory 1) (func (result i64) (i64.load8_u (f32.const 0)))) "type mismatch")
   379  (assert_invalid (module (memory 1) (func (result i64) (i64.load16_s (f32.const 0)))) "type mismatch")
   380  (assert_invalid (module (memory 1) (func (result i64) (i64.load16_u (f32.const 0)))) "type mismatch")
   381  (assert_invalid (module (memory 1) (func (result i64) (i64.load32_s (f32.const 0)))) "type mismatch")
   382  (assert_invalid (module (memory 1) (func (result i64) (i64.load32_u (f32.const 0)))) "type mismatch")
   383  (assert_invalid (module (memory 1) (func (result f32) (f32.load (f32.const 0)))) "type mismatch")
   384  (assert_invalid (module (memory 1) (func (result f64) (f64.load (f32.const 0)))) "type mismatch")
   385  
   386  
   387  (assert_invalid
   388    (module
   389      (memory 0)
   390      (func $type-address-empty
   391        (i32.load) (drop)
   392      )
   393    )
   394    "type mismatch"
   395  )
   396  (assert_invalid
   397    (module
   398      (memory 0)
   399      (func $type-address-empty-in-block
   400        (i32.const 0)
   401        (block (i32.load) (drop))
   402      )
   403    )
   404    "type mismatch"
   405  )
   406  (assert_invalid
   407    (module
   408      (memory 0)
   409      (func $type-address-empty-in-loop
   410        (i32.const 0)
   411        (loop (i32.load) (drop))
   412      )
   413    )
   414    "type mismatch"
   415  )
   416  (assert_invalid
   417    (module
   418      (memory 0)
   419      (func $type-address-empty-in-then
   420        (i32.const 0) (i32.const 0)
   421        (if (then (i32.load) (drop)))
   422      )
   423    )
   424    "type mismatch"
   425  )
   426  (assert_invalid
   427    (module
   428      (memory 0)
   429      (func $type-address-empty-in-else
   430        (i32.const 0) (i32.const 0)
   431        (if (result i32) (then (i32.const 0)) (else (i32.load))) (drop)
   432      )
   433    )
   434    "type mismatch"
   435  )
   436  (assert_invalid
   437    (module
   438      (memory 0)
   439      (func $type-address-empty-in-br
   440        (i32.const 0)
   441        (block (br 0 (i32.load)) (drop))
   442      )
   443    )
   444    "type mismatch"
   445  )
   446  (assert_invalid
   447    (module
   448      (memory 0)
   449      (func $type-address-empty-in-br_if
   450        (i32.const 0)
   451        (block (br_if 0 (i32.load) (i32.const 1)) (drop))
   452      )
   453    )
   454    "type mismatch"
   455  )
   456  (assert_invalid
   457    (module
   458      (memory 0)
   459      (func $type-address-empty-in-br_table
   460        (i32.const 0)
   461        (block (br_table 0 (i32.load)) (drop))
   462      )
   463    )
   464    "type mismatch"
   465  )
   466  (assert_invalid
   467    (module
   468      (memory 0)
   469      (func $type-address-empty-in-return
   470        (return (i32.load)) (drop)
   471      )
   472    )
   473    "type mismatch"
   474  )
   475  (assert_invalid
   476    (module
   477      (memory 0)
   478      (func $type-address-empty-in-select
   479        (select (i32.load) (i32.const 1) (i32.const 2)) (drop)
   480      )
   481    )
   482    "type mismatch"
   483  )
   484  (assert_invalid
   485    (module
   486      (memory 0)
   487      (func $type-address-empty-in-call
   488        (call 1 (i32.load)) (drop)
   489      )
   490      (func (param i32) (result i32) (local.get 0))
   491    )
   492    "type mismatch"
   493  )
   494  (assert_invalid
   495    (module
   496      (memory 0)
   497      (func $f (param i32) (result i32) (local.get 0))
   498      (type $sig (func (param i32) (result i32)))
   499      (table funcref (elem $f))
   500      (func $type-address-empty-in-call_indirect
   501        (block (result i32)
   502          (call_indirect (type $sig)
   503            (i32.load) (i32.const 0)
   504          )
   505          (drop)
   506        )
   507      )
   508    )
   509    "type mismatch"
   510  )
   511  (assert_invalid
   512    (module
   513      (memory 0)
   514      (func $type-address-empty-in-local.set
   515        (local i32)
   516        (local.set 0 (i32.load)) (local.get 0) (drop)
   517      )
   518    )
   519    "type mismatch"
   520  )
   521  (assert_invalid
   522    (module
   523      (memory 0)
   524      (func $type-address-empty-in-local.tee
   525        (local i32)
   526        (local.tee 0 (i32.load)) (drop)
   527      )
   528    )
   529    "type mismatch"
   530  )
   531  (assert_invalid
   532    (module
   533      (memory 0)
   534      (global $x (mut i32) (i32.const 0))
   535      (func $type-address-empty-in-global.set
   536        (global.set $x (i32.load)) (global.get $x) (drop)
   537      )
   538    )
   539    "type mismatch"
   540  )
   541  (assert_invalid
   542    (module
   543      (memory 0)
   544      (func $type-address-empty-in-memory.grow
   545        (memory.grow (i32.load)) (drop)
   546      )
   547    )
   548    "type mismatch"
   549  )
   550  (assert_invalid
   551    (module
   552      (memory 0)
   553      (func $type-address-empty-in-load
   554        (i32.load (i32.load)) (drop)
   555      )
   556    )
   557    "type mismatch"
   558  )
   559  (assert_invalid
   560    (module
   561      (memory 1)
   562      (func $type-address-empty-in-store
   563        (i32.store (i32.load) (i32.const 1))
   564      )
   565    )
   566    "type mismatch"
   567  )