summaryrefslogtreecommitdiff
path: root/test/lit/merge/table_elem.wat
blob: 8177cd75d793ef153fc6b671d57efa5e300d7de6 (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
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; RUN: wasm-merge %s first %s.second second --rename-export-conflicts -all -S -o - | filecheck %s

;; Test we rename tables and element segments properly at the module scope.
;; Table $foo has a name collision, and both of the element segments' names do
;; as well. This test verifies that element segments refer to the right tables
;; even after such name changes.

(module
  ;; CHECK:      (type $vec (array funcref))
  (type $vec (array funcref))

  ;; CHECK:      (type $1 (func))

  ;; CHECK:      (table $foo 1 funcref)
  (table $foo 1 funcref)

  ;; CHECK:      (table $bar 10 funcref)
  (table $bar 10 funcref)

  ;; CHECK:      (table $foo_2 100 funcref)

  ;; CHECK:      (table $other 1000 funcref)

  ;; CHECK:      (elem $a (table $foo) (i32.const 0) func)
  (elem $a (table $foo) (i32.const 0) func)

  ;; CHECK:      (elem $b (table $bar) (i32.const 0) func)
  (elem $b (table $bar) (i32.const 0) func)

  ;; CHECK:      (elem $a_2 (table $foo_2) (i32.const 0) func)

  ;; CHECK:      (elem $b_2 (table $other) (i32.const 0) func)

  ;; CHECK:      (export "keepalive2" (func $keepalive2))

  ;; CHECK:      (export "keepalive2_1" (func $keepalive2_1))

  ;; CHECK:      (func $keepalive2 (type $1)
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (table.get $foo
  ;; CHECK-NEXT:    (i32.const 1)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (table.get $bar
  ;; CHECK-NEXT:    (i32.const 1)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (array.new_elem $vec $a
  ;; CHECK-NEXT:    (i32.const 1)
  ;; CHECK-NEXT:    (i32.const 2)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT:  (drop
  ;; CHECK-NEXT:   (array.new_elem $vec $b
  ;; CHECK-NEXT:    (i32.const 3)
  ;; CHECK-NEXT:    (i32.const 4)
  ;; CHECK-NEXT:   )
  ;; CHECK-NEXT:  )
  ;; CHECK-NEXT: )
  (func $keepalive2 (export "keepalive2")
    (drop
      (table.get $foo
        (i32.const 1)
      )
    )
    (drop
      (table.get $bar
        (i32.const 1)
      )
    )
    ;; GC operations are the only things that can keep alive an elem segment.
    (drop
      (array.new_elem $vec $a
        (i32.const 1)
        (i32.const 2)
      )
    )
    (drop
      (array.new_elem $vec $b
        (i32.const 3)
        (i32.const 4)
      )
    )
  )
)
;; CHECK:      (func $keepalive2_1 (type $1)
;; CHECK-NEXT:  (drop
;; CHECK-NEXT:   (table.get $foo_2
;; CHECK-NEXT:    (i32.const 1)
;; CHECK-NEXT:   )
;; CHECK-NEXT:  )
;; CHECK-NEXT:  (drop
;; CHECK-NEXT:   (table.get $other
;; CHECK-NEXT:    (i32.const 1)
;; CHECK-NEXT:   )
;; CHECK-NEXT:  )
;; CHECK-NEXT:  (drop
;; CHECK-NEXT:   (array.new_elem $vec $a_2
;; CHECK-NEXT:    (i32.const 5)
;; CHECK-NEXT:    (i32.const 6)
;; CHECK-NEXT:   )
;; CHECK-NEXT:  )
;; CHECK-NEXT:  (drop
;; CHECK-NEXT:   (array.new_elem $vec $b_2
;; CHECK-NEXT:    (i32.const 7)
;; CHECK-NEXT:    (i32.const 8)
;; CHECK-NEXT:   )
;; CHECK-NEXT:  )
;; CHECK-NEXT: )