summaryrefslogtreecommitdiff
path: root/test/lit/heap-types.wast
blob: 4613f4894fd15ae099434e3c602c4d5407867603 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.

;; Check that heap types are emitted properly in the binary format. This file
;; contains small modules that each use a single instruction with a heap type.
;; If we forgot to update collectHeapTypes then we would not write out their
;; type, and hit an error during --roundtrip.

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

(module
  (type $struct.A (struct i32))
  (type $struct.B (struct i32))
  ;; CHECK:      (func $test (type $0)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (ref.test (ref none)
  ;; CHECK-NEXT:    (ref.null none)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $test
    (drop
      (ref.test (ref $struct.B) (ref.null $struct.A))
    )
  )
)

(module
  (type $struct.A (struct i32))
  (type $struct.B (struct i32))
  ;; CHECK:      (func $test (type $0)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (ref.cast nullref
  ;; CHECK-NEXT:    (ref.null none)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $test
    ;; Note that this will not round-trip precisely because Binaryen IR will
    ;; apply the more refined type to the cast automatically (in finalize).
    (drop
      (ref.cast (ref null $struct.B) (ref.null $struct.A))
    )
  )
)

(module
  ;; CHECK:      (type $struct.A (struct (field i32)))
  (type $struct.A (struct i32))
  ;; CHECK:      (func $test (type $0)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (struct.new_default $struct.A)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $test
    (drop
      (struct.new_default $struct.A)
    )
  )
)

(module
  ;; CHECK:      (type $vector (array (mut f64)))
  (type $vector (array (mut f64)))
  ;; CHECK:      (func $test (type $0)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (array.new $vector
  ;; CHECK-NEXT:    (f64.const 3.14159)
  ;; CHECK-NEXT:    (i32.const 3)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $test
    (drop
      (array.new $vector
        (f64.const 3.14159)
        (i32.const 3)
      )
    )
  )
)

(module
  ;; CHECK:      (type $vector (array (mut f64)))
  (type $vector (array (mut f64)))
  ;; CHECK:      (func $test (type $0)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (array.new_fixed $vector 4
  ;; CHECK-NEXT:    (f64.const 1)
  ;; CHECK-NEXT:    (f64.const 2)
  ;; CHECK-NEXT:    (f64.const 4)
  ;; CHECK-NEXT:    (f64.const 8)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $test
    (drop
      (array.new_fixed $vector 4
        (f64.const 1)
        (f64.const 2)
        (f64.const 4)
        (f64.const 8)
      )
    )
  )
)

(module
  ;; CHECK:      (type $vector (array (mut f64)))
  (type $vector (array (mut f64)))
  ;; CHECK:      (func $test (type $1) (param $ref (ref $vector)) (param $index i32) (param $value f64) (param $size i32)
  ;; CHECK-NEXT:  (array.fill $vector
  ;; CHECK-NEXT:   (local.get $ref)
  ;; CHECK-NEXT:   (local.get $index)
  ;; CHECK-NEXT:   (local.get $value)
  ;; CHECK-NEXT:   (local.get $size)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $test (param $ref (ref $vector))
              (param $index i32)
              (param $value f64)
              (param $size i32)
    (array.fill $vector
      (local.get $ref)
      (local.get $index)
      (local.get $value)
      (local.get $size)
    )
  )
)

(module
  ;; CHECK:      (type $vector (array (mut i32)))
  (type $vector (array (mut i32)))
  (data "")
  ;; CHECK:      (func $test (type $1) (param $ref (ref $vector)) (param $index i32) (param $offset i32) (param $size i32)
  ;; CHECK-NEXT:  (array.init_data $vector $0
  ;; CHECK-NEXT:   (local.get $ref)
  ;; CHECK-NEXT:   (local.get $index)
  ;; CHECK-NEXT:   (local.get $offset)
  ;; CHECK-NEXT:   (local.get $size)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $test (param $ref (ref $vector))
              (param $index i32)
              (param $offset i32)
              (param $size i32)
    (array.init_data $vector 0
      (local.get $ref)
      (local.get $index)
      (local.get $offset)
      (local.get $size)
    )
  )
)

(module
  ;; CHECK:      (type $vector (array (mut funcref)))
  (type $vector (array (mut funcref)))
  (elem func)
  ;; CHECK:      (func $test (type $1) (param $ref (ref $vector)) (param $index i32) (param $offset i32) (param $size i32)
  ;; CHECK-NEXT:  (array.init_elem $vector $0
  ;; CHECK-NEXT:   (local.get $ref)
  ;; CHECK-NEXT:   (local.get $index)
  ;; CHECK-NEXT:   (local.get $offset)
  ;; CHECK-NEXT:   (local.get $size)
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $test (param $ref (ref $vector))
              (param $index i32)
              (param $offset i32)
              (param $size i32)
    (array.init_elem $vector 0
      (local.get $ref)
      (local.get $index)
      (local.get $offset)
      (local.get $size)
    )
  )
)