summaryrefslogtreecommitdiff
path: root/test/lit/cast-to-basic.wast
blob: 7c45cf8a3e4a4d51e01b2672039d933feb673d32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.

;; Test that casts to basic types round trip properly.

;; RUN: wasm-opt %s -all --roundtrip -S -o - | filecheck %s

(module
  ;; CHECK:      (func $test (type $1) (param $x structref) (result i32)
  ;; CHECK-NEXT:  (ref.test (ref struct)
  ;; CHECK-NEXT:   (local.get $x)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $test (param $x (ref null struct)) (result i32)
    (ref.test (ref struct)
      (local.get $x)
    )
  )

  ;; CHECK:      (func $cast (type $2) (param $x structref)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (ref.cast structref
  ;; CHECK-NEXT:    (local.get $x)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $cast (param $x (ref null struct))
    (drop
      (ref.cast structref
        (local.get $x)
      )
    )
  )

  ;; CHECK:      (func $br (type $0) (param $anyref anyref)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (block $block (result structref)
  ;; CHECK-NEXT:    (drop
  ;; CHECK-NEXT:     (br_on_cast $block anyref (ref struct)
  ;; CHECK-NEXT:      (local.get $anyref)
  ;; CHECK-NEXT:     )
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:    (ref.null none)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $br (param $anyref anyref)
    (drop
      (block $l (result structref)
        (drop
          (br_on_cast $l anyref (ref struct)
            (local.get $anyref)
          )
        )
        (ref.null none)
      )
    )
  )

  ;; CHECK:      (func $br-null (type $0) (param $anyref anyref)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (block $block (result structref)
  ;; CHECK-NEXT:    (drop
  ;; CHECK-NEXT:     (br_on_cast $block anyref structref
  ;; CHECK-NEXT:      (local.get $anyref)
  ;; CHECK-NEXT:     )
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:    (ref.null none)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $br-null (param $anyref anyref)
    (drop
      (block $l (result structref)
        (drop
          (br_on_cast $l anyref structref
            (local.get $anyref)
          )
        )
        (ref.null none)
      )
    )
  )

  ;; CHECK:      (func $br-fail-null (type $0) (param $anyref anyref)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (block $block (result anyref)
  ;; CHECK-NEXT:    (drop
  ;; CHECK-NEXT:     (br_on_cast_fail $block anyref structref
  ;; CHECK-NEXT:      (local.get $anyref)
  ;; CHECK-NEXT:     )
  ;; CHECK-NEXT:    )
  ;; CHECK-NEXT:    (ref.null none)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $br-fail-null (param $anyref anyref)
    (drop
      (block $l (result anyref)
        (drop
          (br_on_cast_fail $l anyref structref
            (local.get $anyref)
          )
        )
        (ref.null none)
      )
    )
  )
)