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
5 ; Test that simple vtables assemble as expected.
7 ; The class hierarchy is:
10 ; struct C : public A;
11 ; struct D : public B;
12 ; Each with a virtual dtor and method foo.
14 target triple = "wasm32-unknown-unknown"
16 %struct.A = type { ptr }
17 %struct.B = type { %struct.A }
18 %struct.C = type { %struct.A }
19 %struct.D = type { %struct.B }
21 @_ZTVN10__cxxabiv117__class_type_infoE = external global ptr
22 @_ZTVN10__cxxabiv120__si_class_type_infoE = external global ptr
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"
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 ptr] [ptr null, ptr @_ZTI1A, ptr @_ZN1AD2Ev, ptr @_ZN1AD0Ev, ptr @_ZN1A3fooEv], 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 ptr] [ptr null, ptr @_ZTI1B, ptr @_ZN1AD2Ev, ptr @_ZN1BD0Ev, ptr @_ZN1B3fooEv], 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 ptr] [ptr null, ptr @_ZTI1C, ptr @_ZN1AD2Ev, ptr @_ZN1CD0Ev, ptr @_ZN1C3fooEv], 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 ptr] [ptr null, ptr @_ZTI1D, ptr @_ZN1AD2Ev, ptr @_ZN1DD0Ev, ptr @_ZN1D3fooEv], align 4
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 { ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i32 2), ptr @_ZTS1A }
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 { ptr, ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv120__si_class_type_infoE, i32 2), ptr @_ZTS1B, ptr @_ZTI1A }
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 { ptr, ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv120__si_class_type_infoE, i32 2), ptr @_ZTS1C, ptr @_ZTI1A }
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 { ptr, ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv120__si_class_type_infoE, i32 2), ptr @_ZTS1D, ptr @_ZTI1B }
114 @g = global i32 0, align 4
116 define void @_ZN1A3fooEv(ptr %this) {
118 store i32 2, ptr @g, align 4
122 define void @_ZN1B3fooEv(ptr %this) {
124 store i32 4, ptr @g, align 4
128 define void @_ZN1C3fooEv(ptr %this) {
130 store i32 6, ptr @g, align 4
134 define void @_ZN1D3fooEv(ptr %this) {
136 store i32 8, ptr @g, align 4
140 define linkonce_odr void @_ZN1AD0Ev(ptr %this) {
142 tail call void @_ZdlPv(ptr %this)
146 define linkonce_odr void @_ZN1BD0Ev(ptr %this) {
148 tail call void @_ZdlPv(ptr %this)
152 define linkonce_odr void @_ZN1CD0Ev(ptr %this) {
154 tail call void @_ZdlPv(ptr %this)
158 define linkonce_odr ptr @_ZN1AD2Ev(ptr returned %this) {
163 define linkonce_odr void @_ZN1DD0Ev(ptr %this) {
165 tail call void @_ZdlPv(ptr %this)
169 declare void @_ZdlPv(ptr)