xref: /llvm-project/lld/test/wasm/duplicate-table-imports.s (revision 1d445a6e7679cc188fd051f7397b7d9ca8ce4f10)
1# RUN: llvm-mc -mattr=+reference-types -triple=wasm32-unknown-unknown -filetype=obj -o %t.o %s
2# RUN: wasm-ld --allow-undefined -o %t1.wasm %t.o
3# RUN: obj2yaml %t1.wasm | FileCheck %s
4
5.tabletype t1, funcref
6.import_module t1, env
7.import_name t1, t
8.globl t1
9
10# Same import module/name/type as `t1`, should be de-duped.
11.tabletype t2, funcref
12.import_module t2, env
13.import_name t2, t
14.globl t2
15
16# Imported as an externref instead of funcref, so should not be de-duped.
17.tabletype t3, externref
18.import_module t3, env
19.import_name t3, t
20.globl t3
21
22.globl _start
23_start:
24  .functype _start () -> ()
25
26  # Read from `t1`
27  i32.const 0
28  table.get t1
29  drop
30
31  # Read from `t2`
32  i32.const 0
33  table.get t2
34  drop
35
36  # Read from `t3`
37  i32.const 0
38  table.get t3
39  drop
40
41  end_function
42
43## XXX: the second imported table has index 1, not 0. I've verified by hand
44## (with `wasm2wat`) that the resulting Wasm file is correct: `t3` does end up
45## at index 1 and our `table.get` instructions are using the proper table index
46## immediates. This is also asserted (less legibly) in the hexdump of the code
47## body below. It looks like there's a bug in how `obj2yaml` disassembles
48## multiple table imports.
49
50# CHECK:        - Type:            IMPORT
51# CHECK-NEXT:     Imports:
52# CHECK-NEXT:       - Module:          env
53# CHECK-NEXT:         Field:           t
54# CHECK-NEXT:         Kind:            TABLE
55# CHECK-NEXT:         Table:
56# CHECK-NEXT:           Index:           0
57# CHECK-NEXT:           ElemType:        FUNCREF
58# CHECK-NEXT:           Limits:
59# CHECK-NEXT:             Minimum:         0x0
60# CHECK-NEXT:       - Module:          env
61# CHECK-NEXT:         Field:           t
62# CHECK-NEXT:         Kind:            TABLE
63# CHECK-NEXT:         Table:
64# CHECK-NEXT:           Index:           0
65# CHECK-NEXT:           ElemType:        EXTERNREF
66# CHECK-NEXT:           Limits:
67# CHECK-NEXT:             Minimum:         0x0
68# CHECK-NEXT:   - Type:
69
70# CHECK:        - Type:            CODE
71# CHECK-NEXT:     Functions:
72# CHECK-NEXT:       - Index:           0
73# CHECK-NEXT:         Locals:          []
74# CHECK-NEXT:         Body:            41002580808080001A41002580808080001A41002581808080001A0B
75# CHECK-NEXT:   - Type:
76