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

     1  ;; Test that control-flow transfer unwinds stack and it can be anything after.
     2  
     3  (module
     4    (func (export "func-unwind-by-unreachable")
     5      (i32.const 3) (i64.const 1) (unreachable)
     6    )
     7    (func (export "func-unwind-by-br")
     8      (i32.const 3) (i64.const 1) (br 0)
     9    )
    10    (func (export "func-unwind-by-br-value") (result i32)
    11      (i32.const 3) (i64.const 1) (br 0 (i32.const 9))
    12    )
    13    (func (export "func-unwind-by-br_if")
    14      (i32.const 3) (i64.const 1) (drop (drop (br_if 0 (i32.const 1))))
    15    )
    16    (func (export "func-unwind-by-br_if-value") (result i32)
    17      (i32.const 3) (i64.const 1) (drop (drop (br_if 0 (i32.const 9) (i32.const 1))))
    18    )
    19    (func (export "func-unwind-by-br_table")
    20      (i32.const 3) (i64.const 1) (br_table 0 (i32.const 0))
    21    )
    22    (func (export "func-unwind-by-br_table-value") (result i32)
    23      (i32.const 3) (i64.const 1) (br_table 0 (i32.const 9) (i32.const 0))
    24    )
    25    (func (export "func-unwind-by-return") (result i32)
    26      (i32.const 3) (i64.const 1) (return (i32.const 9))
    27    )
    28  
    29    (func (export "block-unwind-by-unreachable")
    30      (block (i32.const 3) (i64.const 1) (unreachable))
    31    )
    32    (func (export "block-unwind-by-br") (result i32)
    33      (block (i32.const 3) (i64.const 1) (br 0)) (i32.const 9)
    34    )
    35    (func (export "block-unwind-by-br-value") (result i32)
    36      (block (result i32) (i32.const 3) (i64.const 1) (br 0 (i32.const 9)))
    37    )
    38    (func (export "block-unwind-by-br_if") (result i32)
    39      (block (i32.const 3) (i64.const 1) (drop (drop (br_if 0 (i32.const 1))))) (i32.const 9)
    40    )
    41    (func (export "block-unwind-by-br_if-value") (result i32)
    42      (block (result i32)
    43        (i32.const 3) (i64.const 1) (drop (drop (br_if 0 (i32.const 9) (i32.const 1))))
    44      )
    45    )
    46    (func (export "block-unwind-by-br_table") (result i32)
    47      (block (i32.const 3) (i64.const 1) (br_table 0 (i32.const 0))) (i32.const 9)
    48    )
    49    (func (export "block-unwind-by-br_table-value") (result i32)
    50      (block (result i32)
    51        (i32.const 3) (i64.const 1) (br_table 0 (i32.const 9) (i32.const 0))
    52      )
    53    )
    54    (func (export "block-unwind-by-return") (result i32)
    55      (block (result i32) (i32.const 3) (i64.const 1) (return (i32.const 9)))
    56    )
    57  
    58    (func (export "block-nested-unwind-by-unreachable") (result i32)
    59      (block (result i32) (i32.const 3) (block (i64.const 1) (unreachable)))
    60    )
    61    (func (export "block-nested-unwind-by-br") (result i32)
    62      (block (i32.const 3) (block (i64.const 1) (br 1)) (drop)) (i32.const 9)
    63    )
    64    (func (export "block-nested-unwind-by-br-value") (result i32)
    65      (block (result i32)
    66        (i32.const 3) (block (i64.const 1) (br 1 (i32.const 9)))
    67      )
    68    )
    69    (func (export "block-nested-unwind-by-br_if") (result i32)
    70      (block (i32.const 3) (block (i64.const 1) (drop (br_if 1 (i32.const 1)))) (drop)) (i32.const 9)
    71    )
    72    (func (export "block-nested-unwind-by-br_if-value") (result i32)
    73      (block (result i32)
    74        (i32.const 3) (block (i64.const 1) (drop (drop (br_if 1 (i32.const 9) (i32.const 1)))))
    75      )
    76    )
    77    (func (export "block-nested-unwind-by-br_table") (result i32)
    78      (block
    79        (i32.const 3) (block (i64.const 1) (br_table 1 (i32.const 1)))
    80        (drop)
    81      )
    82      (i32.const 9)
    83    )
    84    (func (export "block-nested-unwind-by-br_table-value") (result i32)
    85      (block (result i32)
    86        (i32.const 3)
    87        (block (i64.const 1) (br_table 1 (i32.const 9) (i32.const 1)))
    88      )
    89    )
    90    (func (export "block-nested-unwind-by-return") (result i32)
    91      (block (result i32)
    92        (i32.const 3) (block (i64.const 1) (return (i32.const 9)))
    93      )
    94    )
    95  
    96    (func (export "unary-after-unreachable") (result i32)
    97      (f32.const 0) (unreachable) (i64.eqz)
    98    )
    99    (func (export "unary-after-br") (result i32)
   100      (block (result i32) (f32.const 0) (br 0 (i32.const 9)) (i64.eqz))
   101    )
   102    (func (export "unary-after-br_if") (result i32)
   103      (block (result i32)
   104        (i64.const 0) (drop (br_if 0 (i32.const 9) (i32.const 1))) (i64.eqz)
   105      )
   106    )
   107    (func (export "unary-after-br_table") (result i32)
   108      (block (result i32)
   109        (f32.const 0) (br_table 0 0 (i32.const 9) (i32.const 0)) (i64.eqz)
   110      )
   111    )
   112    (func (export "unary-after-return") (result i32)
   113      (f32.const 0) (return (i32.const 9)) (i64.eqz)
   114    )
   115  
   116    (func (export "binary-after-unreachable") (result i32)
   117      (f32.const 0) (f64.const 1) (unreachable) (i64.eq)
   118    )
   119    (func (export "binary-after-br") (result i32)
   120      (block (result i32)
   121        (f32.const 0) (f64.const 1) (br 0 (i32.const 9)) (i64.eq)
   122      )
   123    )
   124    (func (export "binary-after-br_if") (result i32)
   125      (block (result i32)
   126        (i64.const 0) (i64.const 1) (drop (br_if 0 (i32.const 9) (i32.const 1)))
   127        (i64.eq)
   128      )
   129    )
   130    (func (export "binary-after-br_table") (result i32)
   131      (block (result i32)
   132        (f32.const 0) (f64.const 1) (br_table 0 (i32.const 9) (i32.const 0))
   133        (i64.eq)
   134      )
   135    )
   136    (func (export "binary-after-return") (result i32)
   137      (f32.const 0) (f64.const 1) (return (i32.const 9)) (i64.eq)
   138    )
   139  
   140    (func (export "select-after-unreachable") (result i32)
   141      (f32.const 0) (f64.const 1) (i64.const 0) (unreachable) (select)
   142    )
   143    (func (export "select-after-br") (result i32)
   144      (block (result i32)
   145        (f32.const 0) (f64.const 1) (i64.const 0) (br 0 (i32.const 9)) (select)
   146      )
   147    )
   148    (func (export "select-after-br_if") (result i32)
   149      (block (result i32)
   150        (i32.const 0) (i32.const 1) (i32.const 0)
   151        (drop (br_if 0 (i32.const 9) (i32.const 1)))
   152        (select)
   153      )
   154    )
   155    (func (export "select-after-br_table") (result i32)
   156      (block (result i32)
   157        (f32.const 0) (f64.const 1) (i64.const 0)
   158        (br_table 0 (i32.const 9) (i32.const 0))
   159        (select)
   160      )
   161    )
   162    (func (export "select-after-return") (result i32)
   163      (f32.const 0) (f64.const 1) (i64.const 1) (return (i32.const 9)) (select)
   164    )
   165  
   166    (func (export "block-value-after-unreachable") (result i32)
   167      (block (result i32) (f32.const 0) (unreachable))
   168    )
   169    (func (export "block-value-after-br") (result i32)
   170      (block (result i32) (f32.const 0) (br 0 (i32.const 9)))
   171    )
   172    (func (export "block-value-after-br_if") (result i32)
   173      (block (result i32)
   174        (i32.const 0) (drop (br_if 0 (i32.const 9) (i32.const 1)))
   175      )
   176    )
   177    (func (export "block-value-after-br_table") (result i32)
   178      (block (result i32)
   179        (f32.const 0) (br_table 0 0 (i32.const 9) (i32.const 0))
   180      )
   181    )
   182    (func (export "block-value-after-return") (result i32)
   183      (block (result i32) (f32.const 0) (return (i32.const 9)))
   184    )
   185  
   186    (func (export "loop-value-after-unreachable") (result i32)
   187      (loop (result i32) (f32.const 0) (unreachable))
   188    )
   189    (func (export "loop-value-after-br") (result i32)
   190      (block (result i32) (loop (result i32) (f32.const 0) (br 1 (i32.const 9))))
   191    )
   192    (func (export "loop-value-after-br_if") (result i32)
   193      (block (result i32)
   194        (loop (result i32)
   195          (i32.const 0) (drop (br_if 1 (i32.const 9) (i32.const 1)))
   196        )
   197      )
   198    )
   199  
   200    (func (export "loop-value-after-br_table") (result i32)
   201      (block (result i32)
   202        (loop (result i32)
   203          (f32.const 0) (br_table 1 1 (i32.const 9) (i32.const 0))
   204        )
   205      )
   206    )
   207    (func (export "loop-value-after-return") (result i32)
   208      (loop (result i32) (f32.const 0) (return (i32.const 9)))
   209    )
   210  )
   211  
   212  (assert_trap (invoke "func-unwind-by-unreachable") "unreachable")
   213  (assert_return (invoke "func-unwind-by-br"))
   214  (assert_return (invoke "func-unwind-by-br-value") (i32.const 9))
   215  (assert_return (invoke "func-unwind-by-br_if"))
   216  (assert_return (invoke "func-unwind-by-br_if-value") (i32.const 9))
   217  (assert_return (invoke "func-unwind-by-br_table"))
   218  (assert_return (invoke "func-unwind-by-br_table-value") (i32.const 9))
   219  (assert_return (invoke "func-unwind-by-return") (i32.const 9))
   220  
   221  (assert_trap (invoke "block-unwind-by-unreachable") "unreachable")
   222  (assert_return (invoke "block-unwind-by-br") (i32.const 9))
   223  (assert_return (invoke "block-unwind-by-br-value") (i32.const 9))
   224  (assert_return (invoke "block-unwind-by-br_if") (i32.const 9))
   225  (assert_return (invoke "block-unwind-by-br_if-value") (i32.const 9))
   226  (assert_return (invoke "block-unwind-by-br_table") (i32.const 9))
   227  (assert_return (invoke "block-unwind-by-br_table-value") (i32.const 9))
   228  (assert_return (invoke "block-unwind-by-return") (i32.const 9))
   229  
   230  (assert_trap (invoke "block-nested-unwind-by-unreachable") "unreachable")
   231  (assert_return (invoke "block-nested-unwind-by-br") (i32.const 9))
   232  (assert_return (invoke "block-nested-unwind-by-br-value") (i32.const 9))
   233  (assert_return (invoke "block-nested-unwind-by-br_if") (i32.const 9))
   234  (assert_return (invoke "block-nested-unwind-by-br_if-value") (i32.const 9))
   235  (assert_return (invoke "block-nested-unwind-by-br_table") (i32.const 9))
   236  (assert_return (invoke "block-nested-unwind-by-br_table-value") (i32.const 9))
   237  (assert_return (invoke "block-nested-unwind-by-return") (i32.const 9))
   238  
   239  (assert_trap (invoke "unary-after-unreachable") "unreachable")
   240  (assert_return (invoke "unary-after-br") (i32.const 9))
   241  (assert_return (invoke "unary-after-br_if") (i32.const 9))
   242  (assert_return (invoke "unary-after-br_table") (i32.const 9))
   243  (assert_return (invoke "unary-after-return") (i32.const 9))
   244  
   245  (assert_trap (invoke "binary-after-unreachable") "unreachable")
   246  (assert_return (invoke "binary-after-br") (i32.const 9))
   247  (assert_return (invoke "binary-after-br_if") (i32.const 9))
   248  (assert_return (invoke "binary-after-br_table") (i32.const 9))
   249  (assert_return (invoke "binary-after-return") (i32.const 9))
   250  
   251  (assert_trap (invoke "select-after-unreachable") "unreachable")
   252  (assert_return (invoke "select-after-br") (i32.const 9))
   253  (assert_return (invoke "select-after-br_if") (i32.const 9))
   254  (assert_return (invoke "select-after-br_table") (i32.const 9))
   255  (assert_return (invoke "select-after-return") (i32.const 9))
   256  
   257  (assert_trap (invoke "block-value-after-unreachable") "unreachable")
   258  (assert_return (invoke "block-value-after-br") (i32.const 9))
   259  (assert_return (invoke "block-value-after-br_if") (i32.const 9))
   260  (assert_return (invoke "block-value-after-br_table") (i32.const 9))
   261  (assert_return (invoke "block-value-after-return") (i32.const 9))
   262  
   263  (assert_trap (invoke "loop-value-after-unreachable") "unreachable")
   264  (assert_return (invoke "loop-value-after-br") (i32.const 9))
   265  (assert_return (invoke "loop-value-after-br_if") (i32.const 9))
   266  (assert_return (invoke "loop-value-after-br_table") (i32.const 9))
   267  (assert_return (invoke "loop-value-after-return") (i32.const 9))