summaryrefslogtreecommitdiffstats
path: root/test/CodeGenCXX/rtti.cpp
blob: 7ba4d56b6633cbd53c3c4e18ec25326aef41d4bb (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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// RUN: clang-cc -I%S -triple x86_64-apple-darwin -std=c++0x -O0 -S %s -o %t.s
// RUN: FileCheck --input-file=%t.s %s

// RUN: clang-cc -I%S -triple x86_64-apple-darwin -std=c++0x -emit-llvm %s -o %t.ll
// RUN: FileCheck -check-prefix LL --input-file=%t.ll %s
// XFAIL: *

#include <typeinfo>

class test1_B1 {
  virtual void foo() { }
};
class test1_B2 : public test1_B1 {
  virtual void foo() { }
};
class test1_B3 : public test1_B2, public test1_B1 {
  virtual void foo() { }
};
class test1_B4 : virtual public test1_B3 {
  virtual void foo() { }
};
class test1_B5 : virtual test1_B3, test1_B4 {
  virtual void foo() { }
};
class test1_B6 {
  virtual void foo() { }
};
class test1_B7 : public test1_B6, public test1_B5 {
  virtual void foo() { }
};
class test1_D : public test1_B7 {
  virtual void foo() { }
} d1;

// CHECK:__ZTI7test1_D:
// CHECK-NEXT: .quad (__ZTVN10__cxxabiv120__si_class_type_infoE) + 16
// CHECK-NEXT: .quad __ZTS7test1_D
// CHECK-NEXT: .quad __ZTI8test1_B7

// CHECK:     __ZTSPVi:
// CHECK-NEXT: .asciz "PVi"

// CHECK:     __ZTIPVi:
// CHECK-NEXT: .quad  (__ZTVN10__cxxabiv119__pointer_type_infoE) + 16
// CHECK-NEXT: .quad  __ZTSPVi
// CHECK-NEXT: .long  2
// CHECK-NEXT: .space 4
// CHECK-NEXT: .quad  __ZTIi

// CHECK:      .globl __ZTS7test3_A
// CHECK-NEXT: .weak_definition __ZTS7test3_A
// CHECK:     __ZTS7test3_A:
// CHECK-NEXT: .asciz	"7test3_A"

// CHECK:     __ZTIM7test3_Ai:
// CHECK-NEXT: .quad  (__ZTVN10__cxxabiv129__pointer_to_member_type_infoE) + 16
// CHECK-NEXT: .quad  __ZTSM7test3_Ai
// CHECK-NEXT: .space 4
// CHECK-NEXT: .space 4
// CHECK-NEXT: .quad  __ZTIi
// CHECK-NEXT: .quad  __ZTI7test3_A

// CHECK:     __ZTIM7test3_Ii:
// CHECK-NEXT: .quad  (__ZTVN10__cxxabiv129__pointer_to_member_type_infoE) + 16
// CHECK-NEXT: .quad  __ZTSM7test3_Ii
// CHECK-NEXT: .long  16
// CHECK-NEXT: .space 4
// CHECK-NEXT: .quad  __ZTIi
// CHECK-NEXT: .quad  __ZTI7test3_I

// CHECK:     .private_extern __ZTIFvvE
// CHECK:     .globl __ZTIFvvE
// CHECK:     .weak_definition __ZTIFvvE
// CHECK:     __ZTIFvvE:
// CHECK-NEXT: 	.quad	(__ZTVN10__cxxabiv120__function_type_infoE) + 16
// CHECK-NEXT: 	.quad	__ZTSFvvE

// CHECK:     __ZTIM7test3_AFvvE:
// CHECK-NEXT: 	.quad	(__ZTVN10__cxxabiv129__pointer_to_member_type_infoE) + 16
// CHECK-NEXT: 	.quad	__ZTSM7test3_AFvvE
// CHECK-NEXT: 	.space	4
// CHECK-NEXT: 	.space	4
// CHECK-NEXT: 	.quad	__ZTIFvvE
// CHECK-NEXT: 	.quad	__ZTI7test3_A

// CHECK:__ZTI8test1_B7:
// CHECK-NEXT: .quad (__ZTVN10__cxxabiv121__vmi_class_type_infoE) + 16
// CHECK-NEXT: .quad __ZTS8test1_B7
// CHECK-NEXT: .long 3
// CHECK-NEXT: .long 2
// CHECK-NEXT: .quad __ZTI8test1_B6
// CHECK-NEXT: .quad 2
// CHECK-NEXT: .quad __ZTI8test1_B5
// CHECK-NEXT: .quad 2050

// CHECK:__ZTI8test1_B5:
// CHECK-NEXT: .quad (__ZTVN10__cxxabiv121__vmi_class_type_infoE) + 16
// CHECK-NEXT: .quad __ZTS8test1_B5
// CHECK-NEXT: .long 3
// CHECK-NEXT: .long 2
// CHECK-NEXT: .quad __ZTI8test1_B3
// CHECK-NEXT: .quad 18446744073709545473
// CHECK-NEXT: .quad __ZTI8test1_B4
// CHECK-NEXT: .space 8

// CHECK:__ZTI8test1_B4:
// CHECK-NEXT: .quad (__ZTVN10__cxxabiv121__vmi_class_type_infoE) + 16
// CHECK-NEXT: .quad __ZTS8test1_B4
// CHECK-NEXT: .long 1
// CHECK-NEXT: .long 1
// CHECK-NEXT: .quad __ZTI8test1_B3
// CHECK-NEXT: .quad 18446744073709545475

// CHECK:__ZTI8test1_B6:
// CHECK-NEXT: .quad (__ZTVN10__cxxabiv117__class_type_infoE) + 16
// CHECK-NEXT: .quad __ZTS8test1_B6

// CHECK:__ZTI8test1_B3:
// CHECK-NEXT: .quad (__ZTVN10__cxxabiv121__vmi_class_type_infoE) + 16
// CHECK-NEXT: .quad __ZTS8test1_B3
// CHECK-NEXT: .long 1
// CHECK-NEXT: .long 2
// CHECK-NEXT: .quad __ZTI8test1_B2
// CHECK-NEXT: .quad 2
// CHECK-NEXT: .quad __ZTI8test1_B1
// CHECK-NEXT: .quad 2050

// CHECK:__ZTS8test1_B1:
// CHECK-NEXT: .asciz "8test1_B1"

// CHECK:__ZTI8test1_B1:
// CHECK-NEXT: .quad (__ZTVN10__cxxabiv117__class_type_infoE) + 16
// CHECK-NEXT:. quad __ZTS8test1_B1

// CHECK:__ZTS8test1_B2:
// CHECK-NEXT: .asciz "8test1_B2"

// CHECK:__ZTI8test1_B2:
// CHECK-NEXT: .quad (__ZTVN10__cxxabiv120__si_class_type_infoE) + 16
// CHECK-NEXT: .quad __ZTS8test1_B2
// CHECK-NEXT: .quad __ZTI8test1_B1

class NP { };
void test2_1();
void test2_2(test1_D *dp) {
  test1_D &d = *dp;
  if (typeid(d) == typeid(test1_D))
    test2_1();
  if (typeid(NP) == typeid(test1_D))
    test2_1();
  if (typeid(((*(dp)))) == typeid(test1_D))
    test2_1();
  if (typeid(int) == typeid(float))
    test2_1();
  if (typeid(int*) == typeid(const int *))
    test2_1();
}

// CHECK-LL:define void @_Z7test2_2P7test1_D(%class.test1_B7* %dp) nounwind {
// CHECK-LL:       %tmp1 = load %class.test1_B7** %d
// CHECK-LL-NEXT:  %0 = bitcast %class.test1_B7* %tmp1 to %"class.std::type_info"***
// CHECK-LL-NEXT:  %vtable = load %"class.std::type_info"*** %0
// CHECK-LL-NEXT:  %1 = getelementptr inbounds %"class.std::type_info"** %vtable, i64 -1
// CHECK-LL-NEXT:  %2 = load %"class.std::type_info"** %1
// CHECK-LL-NEXT:  %call = call zeroext i1 @_ZNKSt9type_infoeqERKS_(%"class.std::type_info"* %2, %"class.std::type_info"* bitcast (%{{[0-9]*}}* @_ZTI7test1_D to %"class.std::type_info"*))

// CHECK-LL:       %call2 = call zeroext i1 @_ZNKSt9type_infoeqERKS_(%"class.std::type_info"* bitcast (%{{[0-9]*}}* @_ZTI2NP to %"class.std::type_info"*), %"class.std::type_info"* bitcast (%{{[0-9]*}}* @_ZTI7test1_D to %"class.std::type_info"*))

// CHECK-LL:       %3 = bitcast %class.test1_B7* %tmp5 to %"class.std::type_info"***
// CHECK-LL-NEXT:  %4 = icmp ne %"class.std::type_info"*** %3, null
// CHECK-LL-NEXT:  br i1 %4, label %6, label %5
// CHECK-LL:     ; <label>:5
// CHECK-LL-NEXT:  call void @__cxa_bad_typeid()
// CHECK-LL-NEXT:  unreachable
// CHECK-LL:     ; <label>:6
// CHECK-LL-NEXT:  %vtable6 = load %"class.std::type_info"*** %3
// CHECK-LL-NEXT:  %7 = getelementptr inbounds %"class.std::type_info"** %vtable6, i64 -1
// CHECK-LL-NEXT:  %8 = load %"class.std::type_info"** %7
// CHECK-LL-NEXT:  %call7 = call zeroext i1 @_ZNKSt9type_infoeqERKS_(%"class.std::type_info"* %8, %"class.std::type_info"* bitcast (%{{[0-9]*}}* @_ZTI7test1_D to %"class.std::type_info"*))

// CHECK-LL:       %call10 = call zeroext i1 @_ZNKSt9type_infoeqERKS_(%"class.std::type_info"* bitcast (i8** @_ZTIi to %"class.std::type_info"*), %"class.std::type_info"* bitcast (i8** @_ZTIf to %"class.std::type_info"*))

// CHECK-LL:       %call13 = call zeroext i1 @_ZNKSt9type_infoeqERKS_(%"class.std::type_info"* bitcast (i8** @_ZTIPi to %"class.std::type_info"*), %"class.std::type_info"* bitcast (i8** @_ZTIPKi to %"class.std::type_info"*))

class test3_A { };
class test3_I;
int (test3_A::*pmd);
int (test3_I::*i_pmd);
void (test3_A::*pmf)();
int test3() {
  if (typeid(volatile int *) == typeid(int *))
    return 1;
  if (typeid(pmd) == typeid(i_pmd))
    return 1;
  if (typeid(pmd) == typeid(pmf))
    return 1;
  return 0;
  enum a { };
  if (typeid(int[5]) == typeid(enum a))
    return 0;
}

bool test4(std::type_info* __pointee) {
  return *__pointee == typeid (void);
}