1; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=TYPEINFONAME
2; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=VTABLE
3; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s --check-prefix=TYPEINFO
4
5; Test that simple vtables assemble as expected.
6;
7; The class hierarchy is:
8;   struct A;
9;   struct B : public A;
10;   struct C : public A;
11;   struct D : public B;
12; Each with a virtual dtor and method foo.
13
14target triple = "wasm32-unknown-unknown"
15
16%struct.A = type { i32 (...)** }
17%struct.B = type { %struct.A }
18%struct.C = type { %struct.A }
19%struct.D = type { %struct.B }
20
21@_ZTVN10__cxxabiv117__class_type_infoE = external global i8*
22@_ZTVN10__cxxabiv120__si_class_type_infoE = external global i8*
23
24; TYPEINFONAME-LABEL: _ZTS1A:
25; TYPEINFONAME-NEXT: .asciz "1A"
26@_ZTS1A = constant [3 x i8] c"1A\00"
27; TYPEINFONAME-LABEL: _ZTS1B:
28; TYPEINFONAME-NEXT: .asciz "1B"
29@_ZTS1B = constant [3 x i8] c"1B\00"
30; TYPEINFONAME-LABEL: _ZTS1C:
31; TYPEINFONAME-NEXT: .asciz "1C"
32@_ZTS1C = constant [3 x i8] c"1C\00"
33; TYPEINFONAME-LABEL: _ZTS1D:
34; TYPEINFONAME-NEXT: .asciz "1D"
35@_ZTS1D = constant [3 x i8] c"1D\00"
36
37; VTABLE:       .type _ZTV1A,@object
38; VTABLE-NEXT:  .section .rodata._ZTV1A,
39; VTABLE-NEXT:  .globl _ZTV1A
40; VTABLE-LABEL: _ZTV1A:
41; VTABLE-NEXT:  .int32 0
42; VTABLE-NEXT:  .int32 _ZTI1A
43; VTABLE-NEXT:  .int32 _ZN1AD2Ev
44; VTABLE-NEXT:  .int32 _ZN1AD0Ev
45; VTABLE-NEXT:  .int32 _ZN1A3fooEv
46; VTABLE-NEXT:  .size _ZTV1A, 20
47@_ZTV1A = constant [5 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1A to i8*), i8* bitcast (%struct.A* (%struct.A*)* @_ZN1AD2Ev to i8*), i8* bitcast (void (%struct.A*)* @_ZN1AD0Ev to i8*), i8* bitcast (void (%struct.A*)* @_ZN1A3fooEv to i8*)], align 4
48; VTABLE:       .type _ZTV1B,@object
49; VTABLE-NEXT:  .section .rodata._ZTV1B,
50; VTABLE-NEXT:  .globl _ZTV1B
51; VTABLE-LABEL: _ZTV1B:
52; VTABLE-NEXT:  .int32 0
53; VTABLE-NEXT:  .int32 _ZTI1B
54; VTABLE-NEXT:  .int32 _ZN1AD2Ev
55; VTABLE-NEXT:  .int32 _ZN1BD0Ev
56; VTABLE-NEXT:  .int32 _ZN1B3fooEv
57; VTABLE-NEXT:  .size _ZTV1B, 20
58@_ZTV1B = constant [5 x i8*] [i8* null, i8* bitcast ({ i8*, i8*, i8* }* @_ZTI1B to i8*), i8* bitcast (%struct.A* (%struct.A*)* @_ZN1AD2Ev to i8*), i8* bitcast (void (%struct.B*)* @_ZN1BD0Ev to i8*), i8* bitcast (void (%struct.B*)* @_ZN1B3fooEv to i8*)], align 4
59; VTABLE:       .type _ZTV1C,@object
60; VTABLE-NEXT:  .section .rodata._ZTV1C,
61; VTABLE-NEXT:  .globl _ZTV1C
62; VTABLE-LABEL: _ZTV1C:
63; VTABLE-NEXT:  .int32 0
64; VTABLE-NEXT:  .int32 _ZTI1C
65; VTABLE-NEXT:  .int32 _ZN1AD2Ev
66; VTABLE-NEXT:  .int32 _ZN1CD0Ev
67; VTABLE-NEXT:  .int32 _ZN1C3fooEv
68; VTABLE-NEXT:  .size _ZTV1C, 20
69@_ZTV1C = constant [5 x i8*] [i8* null, i8* bitcast ({ i8*, i8*, i8* }* @_ZTI1C to i8*), i8* bitcast (%struct.A* (%struct.A*)* @_ZN1AD2Ev to i8*), i8* bitcast (void (%struct.C*)* @_ZN1CD0Ev to i8*), i8* bitcast (void (%struct.C*)* @_ZN1C3fooEv to i8*)], align 4
70; VTABLE:       .type _ZTV1D,@object
71; VTABLE-NEXT:  .section .rodata._ZTV1D,
72; VTABLE-NEXT:  .globl _ZTV1D
73; VTABLE-LABEL: _ZTV1D:
74; VTABLE-NEXT:  .int32 0
75; VTABLE-NEXT:  .int32 _ZTI1D
76; VTABLE-NEXT:  .int32 _ZN1AD2Ev
77; VTABLE-NEXT:  .int32 _ZN1DD0Ev
78; VTABLE-NEXT:  .int32 _ZN1D3fooEv
79; VTABLE-NEXT:  .size _ZTV1D, 20
80@_ZTV1D = constant [5 x i8*] [i8* null, i8* bitcast ({ i8*, i8*, i8* }* @_ZTI1D to i8*), i8* bitcast (%struct.A* (%struct.A*)* @_ZN1AD2Ev to i8*), i8* bitcast (void (%struct.D*)* @_ZN1DD0Ev to i8*), i8* bitcast (void (%struct.D*)* @_ZN1D3fooEv to i8*)], align 4
81
82; TYPEINFO:       .type _ZTI1A,@object
83; TYPEINFO:       .globl _ZTI1A
84; TYPEINFO-LABEL: _ZTI1A:
85; TYPEINFO-NEXT:  .int32 _ZTVN10__cxxabiv117__class_type_infoE+8
86; TYPEINFO-NEXT:  .int32 _ZTS1A
87; TYPEINFO-NEXT:  .size _ZTI1A, 8
88@_ZTI1A = constant { i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv117__class_type_infoE, i32 2) to i8*), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @_ZTS1A, i32 0, i32 0) }
89; TYPEINFO:       .type _ZTI1B,@object
90; TYPEINFO:       .globl _ZTI1B
91; TYPEINFO-LABEL: _ZTI1B:
92; TYPEINFO-NEXT:  .int32 _ZTVN10__cxxabiv120__si_class_type_infoE+8
93; TYPEINFO-NEXT:  .int32 _ZTS1B
94; TYPEINFO-NEXT:  .int32 _ZTI1A
95; TYPEINFO-NEXT:  .size _ZTI1B, 12
96@_ZTI1B = constant { i8*, i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv120__si_class_type_infoE, i32 2) to i8*), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @_ZTS1B, i32 0, i32 0), i8* bitcast ({ i8*, i8* }* @_ZTI1A to i8*) }
97; TYPEINFO:       .type _ZTI1C,@object
98; TYPEINFO:       .globl _ZTI1C
99; TYPEINFO-LABEL: _ZTI1C:
100; TYPEINFO-NEXT:  .int32 _ZTVN10__cxxabiv120__si_class_type_infoE+8
101; TYPEINFO-NEXT:  .int32 _ZTS1C
102; TYPEINFO-NEXT:  .int32 _ZTI1A
103; TYPEINFO-NEXT:  .size _ZTI1C, 12
104@_ZTI1C = constant { i8*, i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv120__si_class_type_infoE, i32 2) to i8*), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @_ZTS1C, i32 0, i32 0), i8* bitcast ({ i8*, i8* }* @_ZTI1A to i8*) }
105; TYPEINFO:       .type _ZTI1D,@object
106; TYPEINFO:       .globl _ZTI1D
107; TYPEINFO-LABEL: _ZTI1D:
108; TYPEINFO-NEXT:  .int32 _ZTVN10__cxxabiv120__si_class_type_infoE+8
109; TYPEINFO-NEXT:  .int32 _ZTS1D
110; TYPEINFO-NEXT:  .int32 _ZTI1B
111; TYPEINFO-NEXT:  .size _ZTI1D, 12
112@_ZTI1D = constant { i8*, i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv120__si_class_type_infoE, i32 2) to i8*), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @_ZTS1D, i32 0, i32 0), i8* bitcast ({ i8*, i8*, i8* }* @_ZTI1B to i8*) }
113
114@g = global i32 0, align 4
115
116define void @_ZN1A3fooEv(%struct.A* %this) {
117entry:
118  store i32 2, i32* @g, align 4
119  ret void
120}
121
122define void @_ZN1B3fooEv(%struct.B* %this) {
123entry:
124  store i32 4, i32* @g, align 4
125  ret void
126}
127
128define void @_ZN1C3fooEv(%struct.C* %this) {
129entry:
130  store i32 6, i32* @g, align 4
131  ret void
132}
133
134define void @_ZN1D3fooEv(%struct.D* %this) {
135entry:
136  store i32 8, i32* @g, align 4
137  ret void
138}
139
140define linkonce_odr void @_ZN1AD0Ev(%struct.A* %this) {
141entry:
142  %0 = bitcast %struct.A* %this to i8*
143  tail call void @_ZdlPv(i8* %0)
144  ret void
145}
146
147define linkonce_odr void @_ZN1BD0Ev(%struct.B* %this) {
148entry:
149  %0 = bitcast %struct.B* %this to i8*
150  tail call void @_ZdlPv(i8* %0)
151  ret void
152}
153
154define linkonce_odr void @_ZN1CD0Ev(%struct.C* %this) {
155entry:
156  %0 = bitcast %struct.C* %this to i8*
157  tail call void @_ZdlPv(i8* %0)
158  ret void
159}
160
161define linkonce_odr %struct.A* @_ZN1AD2Ev(%struct.A* returned %this) {
162entry:
163  ret %struct.A* %this
164}
165
166define linkonce_odr void @_ZN1DD0Ev(%struct.D* %this) {
167entry:
168  %0 = bitcast %struct.D* %this to i8*
169  tail call void @_ZdlPv(i8* %0)
170  ret void
171}
172
173declare void @_ZdlPv(i8*)
174