xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/rtti-linkage.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BOTH
2*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fvisibility hidden -emit-llvm -o - | FileCheck -check-prefix=CHECK-WITH-HIDDEN -check-prefix=CHECK-BOTH %s
3f4a2713aSLionel Sambuc 
4f4a2713aSLionel Sambuc #include <typeinfo>
5f4a2713aSLionel Sambuc 
6*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTSP1C = internal constant
7*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTS1C = internal constant
8*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTI1C = internal constant
9*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTIP1C = internal constant
10*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTSPP1C = internal constant
11*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTIPP1C = internal constant
12*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTSM1Ci = internal constant
13*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTIM1Ci = internal constant
14*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTSPM1Ci = internal constant
15*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTIPM1Ci = internal constant
16*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTSM1CS_ = internal constant
17*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTIM1CS_ = internal constant
18*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTSM1CPS_ = internal constant
19*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTIM1CPS_ = internal constant
20*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTSM1A1C = internal constant
21*0a6a1f1dSLionel Sambuc // CHECK: _ZTS1A = linkonce_odr constant
22*0a6a1f1dSLionel Sambuc // CHECK-WITH-HIDDEN: _ZTS1A = linkonce_odr hidden constant
23*0a6a1f1dSLionel Sambuc // CHECK: _ZTI1A = linkonce_odr constant
24*0a6a1f1dSLionel Sambuc // CHECK-WITH-HIDDEN: _ZTI1A = linkonce_odr hidden constant
25*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTIM1A1C = internal constant
26*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTSM1AP1C = internal constant
27*0a6a1f1dSLionel Sambuc // CHECK-BOTH: _ZTIM1AP1C = internal constant
28*0a6a1f1dSLionel Sambuc 
29f4a2713aSLionel Sambuc // CHECK-WITH-HIDDEN: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
30f4a2713aSLionel Sambuc // CHECK-WITH-HIDDEN: @_ZTSPK2T4 = linkonce_odr hidden constant
31f4a2713aSLionel Sambuc // CHECK-WITH-HIDDEN: @_ZTS2T4 = linkonce_odr hidden constant
32*0a6a1f1dSLionel Sambuc // CHECK-WITH-HIDDEN: @_ZTI2T4 = linkonce_odr hidden constant
33*0a6a1f1dSLionel Sambuc // CHECK-WITH-HIDDEN: @_ZTIPK2T4 = linkonce_odr hidden constant
34*0a6a1f1dSLionel Sambuc // CHECK-WITH-HIDDEN: @_ZTSZ2t5vE1A = internal constant
35*0a6a1f1dSLionel Sambuc // CHECK-WITH-HIDDEN: @_ZTIZ2t5vE1A = internal constant
36*0a6a1f1dSLionel Sambuc // CHECK-WITH-HIDDEN: @_ZTSPZ2t7vE1A = linkonce_odr hidden constant
37*0a6a1f1dSLionel Sambuc // CHECK-WITH-HIDDEN: @_ZTSZ2t7vE1A = linkonce_odr hidden constant
38*0a6a1f1dSLionel Sambuc // CHECK-WITH-HIDDEN: @_ZTIZ2t7vE1A = linkonce_odr hidden constant
39*0a6a1f1dSLionel Sambuc // CHECK-WITH-HIDDEN: @_ZTIPZ2t7vE1A = linkonce_odr hidden constant
40*0a6a1f1dSLionel Sambuc // CHECK-WITH-HIDDEN: @_ZTSZ2t6vE1A = linkonce_odr hidden constant
41*0a6a1f1dSLionel Sambuc // CHECK-WITH-HIDDEN: @_ZTIZ2t6vE1A = linkonce_odr hidden constant
42f4a2713aSLionel Sambuc 
43f4a2713aSLionel Sambuc // CHECK: _ZTSN12_GLOBAL__N_11DE = internal constant
44*0a6a1f1dSLionel Sambuc // CHECK: _ZTIN12_GLOBAL__N_11DE = internal constant
45f4a2713aSLionel Sambuc // CHECK: _ZTSPN12_GLOBAL__N_11DE = internal constant
46*0a6a1f1dSLionel Sambuc // CHECK: _ZTIPN12_GLOBAL__N_11DE = internal constant
47f4a2713aSLionel Sambuc // CHECK: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
48*0a6a1f1dSLionel Sambuc // CHECK: _ZTIFN12_GLOBAL__N_11DEvE = internal constant
49f4a2713aSLionel Sambuc // CHECK: _ZTSFvN12_GLOBAL__N_11DEE = internal constant
50*0a6a1f1dSLionel Sambuc // CHECK: _ZTIFvN12_GLOBAL__N_11DEE = internal constant
51f4a2713aSLionel Sambuc // CHECK: _ZTSPFvvE = linkonce_odr constant
52f4a2713aSLionel Sambuc // CHECK: _ZTSFvvE = linkonce_odr constant
53*0a6a1f1dSLionel Sambuc // CHECK: _ZTIFvvE = linkonce_odr constant
54*0a6a1f1dSLionel Sambuc // CHECK: _ZTIPFvvE = linkonce_odr constant
55f4a2713aSLionel Sambuc // CHECK: _ZTSN12_GLOBAL__N_11EE = internal constant
56*0a6a1f1dSLionel Sambuc // CHECK: _ZTIN12_GLOBAL__N_11EE = internal constant
57f4a2713aSLionel Sambuc // CHECK: _ZTSA10_i = linkonce_odr constant
58*0a6a1f1dSLionel Sambuc // CHECK: _ZTIA10_i = linkonce_odr constant
59*0a6a1f1dSLionel Sambuc // CHECK: _ZTI1TILj0EE = linkonce_odr constant
60*0a6a1f1dSLionel Sambuc // CHECK: _ZTI1TILj1EE = weak_odr constant
61f4a2713aSLionel Sambuc // CHECK: _ZTI1TILj2EE = external constant
62*0a6a1f1dSLionel Sambuc // CHECK: _ZTSZ2t5vE1A = internal constant
63*0a6a1f1dSLionel Sambuc // CHECK: _ZTIZ2t5vE1A = internal constant
64f4a2713aSLionel Sambuc // CHECK: _ZTS1B = constant
65*0a6a1f1dSLionel Sambuc // CHECK: _ZTI1B = constant
66f4a2713aSLionel Sambuc // CHECK: _ZTS1F = linkonce_odr constant
67*0a6a1f1dSLionel Sambuc // CHECK: _ZTSPZ2t7vE1A = linkonce_odr constant
68*0a6a1f1dSLionel Sambuc // CHECK: _ZTSZ2t7vE1A = linkonce_odr constant
69*0a6a1f1dSLionel Sambuc // CHECK: _ZTIZ2t7vE1A = linkonce_odr constant
70*0a6a1f1dSLionel Sambuc // CHECK: _ZTIPZ2t7vE1A = linkonce_odr constant
71*0a6a1f1dSLionel Sambuc // CHECK: _ZTSZ2t6vE1A = linkonce_odr constant
72*0a6a1f1dSLionel Sambuc // CHECK: _ZTIZ2t6vE1A = linkonce_odr constant
73f4a2713aSLionel Sambuc 
74f4a2713aSLionel Sambuc // CHECK: _ZTIN12_GLOBAL__N_11DE to
75f4a2713aSLionel Sambuc 
76f4a2713aSLionel Sambuc // A has no key function, so its RTTI data should be linkonce_odr.
77f4a2713aSLionel Sambuc struct A { };
78f4a2713aSLionel Sambuc 
79f4a2713aSLionel Sambuc // B has a key function defined in the translation unit, so the RTTI data should
80f4a2713aSLionel Sambuc // be emitted in this translation unit and have external linkage.
81f4a2713aSLionel Sambuc struct B : A {
82f4a2713aSLionel Sambuc   virtual void f();
83f4a2713aSLionel Sambuc };
f()84f4a2713aSLionel Sambuc void B::f() { }
85f4a2713aSLionel Sambuc 
86f4a2713aSLionel Sambuc // C is an incomplete class type, so any direct or indirect pointer types should have
87f4a2713aSLionel Sambuc // internal linkage, as should the type info for C itself.
88f4a2713aSLionel Sambuc struct C;
89f4a2713aSLionel Sambuc 
t1()90f4a2713aSLionel Sambuc void t1() {
91f4a2713aSLionel Sambuc   (void)typeid(C*);
92f4a2713aSLionel Sambuc   (void)typeid(C**);
93f4a2713aSLionel Sambuc   (void)typeid(int C::*);
94f4a2713aSLionel Sambuc   (void)typeid(int C::**);
95f4a2713aSLionel Sambuc   (void)typeid(C C::*);
96f4a2713aSLionel Sambuc   (void)typeid(C *C::*);
97f4a2713aSLionel Sambuc   (void)typeid(C A::*);
98f4a2713aSLionel Sambuc   (void)typeid(C* A::*);
99f4a2713aSLionel Sambuc }
100f4a2713aSLionel Sambuc 
101f4a2713aSLionel Sambuc namespace {
102f4a2713aSLionel Sambuc   // D is inside an anonymous namespace, so all type information related to D should have
103f4a2713aSLionel Sambuc   // internal linkage.
104f4a2713aSLionel Sambuc   struct D { };
105f4a2713aSLionel Sambuc 
106f4a2713aSLionel Sambuc   // E is also inside an anonymous namespace.
107f4a2713aSLionel Sambuc   enum E { };
108f4a2713aSLionel Sambuc 
109f4a2713aSLionel Sambuc };
110f4a2713aSLionel Sambuc 
111f4a2713aSLionel Sambuc // F has a key function defined in the translation unit, but it is inline so the RTTI
112f4a2713aSLionel Sambuc // data should be emitted with linkonce_odr linkage.
113f4a2713aSLionel Sambuc struct F {
114f4a2713aSLionel Sambuc   virtual void f();
115f4a2713aSLionel Sambuc };
116f4a2713aSLionel Sambuc 
f()117f4a2713aSLionel Sambuc inline void F::f() { }
118f4a2713aSLionel Sambuc const D getD();
119f4a2713aSLionel Sambuc 
t2()120f4a2713aSLionel Sambuc const std::type_info &t2() {
121f4a2713aSLionel Sambuc   (void)typeid(const D);
122f4a2713aSLionel Sambuc   (void)typeid(D *);
123f4a2713aSLionel Sambuc   (void)typeid(D (*)());
124f4a2713aSLionel Sambuc   (void)typeid(void (*)(D));
125f4a2713aSLionel Sambuc   (void)typeid(void (*)(D&));
126f4a2713aSLionel Sambuc   // The exception specification is not part of the RTTI descriptor, so it should not have
127f4a2713aSLionel Sambuc   // internal linkage.
128f4a2713aSLionel Sambuc   (void)typeid(void (*)() throw (D));
129f4a2713aSLionel Sambuc 
130f4a2713aSLionel Sambuc   (void)typeid(E);
131f4a2713aSLionel Sambuc 
132f4a2713aSLionel Sambuc   return typeid(getD());
133f4a2713aSLionel Sambuc }
134f4a2713aSLionel Sambuc 
135f4a2713aSLionel Sambuc namespace Arrays {
136f4a2713aSLionel Sambuc   struct A {
137f4a2713aSLionel Sambuc     static const int a[10];
138f4a2713aSLionel Sambuc   };
f()139f4a2713aSLionel Sambuc   const std::type_info &f() {
140f4a2713aSLionel Sambuc     return typeid(A::a);
141f4a2713aSLionel Sambuc   }
142f4a2713aSLionel Sambuc }
143f4a2713aSLionel Sambuc 
144f4a2713aSLionel Sambuc template <unsigned N> class T {
anchor()145f4a2713aSLionel Sambuc   virtual void anchor() {}
146f4a2713aSLionel Sambuc };
147f4a2713aSLionel Sambuc template class T<1>;
148f4a2713aSLionel Sambuc template <> class T<2> { virtual void anchor(); };
t3()149f4a2713aSLionel Sambuc void t3() {
150f4a2713aSLionel Sambuc   (void) typeid(T<0>);
151f4a2713aSLionel Sambuc   (void) typeid(T<1>);
152f4a2713aSLionel Sambuc   (void) typeid(T<2>);
153f4a2713aSLionel Sambuc }
154f4a2713aSLionel Sambuc 
155f4a2713aSLionel Sambuc // rdar://problem/8778973
156f4a2713aSLionel Sambuc struct T4 {};
t4(const T4 * ptr)157f4a2713aSLionel Sambuc void t4(const T4 *ptr) {
158f4a2713aSLionel Sambuc   const void *value = &typeid(ptr);
159f4a2713aSLionel Sambuc }
160*0a6a1f1dSLionel Sambuc 
161*0a6a1f1dSLionel Sambuc // rdar://16265084
t5()162*0a6a1f1dSLionel Sambuc void t5() {
163*0a6a1f1dSLionel Sambuc   struct A {};
164*0a6a1f1dSLionel Sambuc   const void *value = &typeid(A);
165*0a6a1f1dSLionel Sambuc }
166*0a6a1f1dSLionel Sambuc 
t6()167*0a6a1f1dSLionel Sambuc inline void t6() {
168*0a6a1f1dSLionel Sambuc   struct A {};
169*0a6a1f1dSLionel Sambuc   const void *value = &typeid(A);
170*0a6a1f1dSLionel Sambuc }
t6_helper()171*0a6a1f1dSLionel Sambuc void t6_helper() {
172*0a6a1f1dSLionel Sambuc   t6();
173*0a6a1f1dSLionel Sambuc }
174*0a6a1f1dSLionel Sambuc 
t7()175*0a6a1f1dSLionel Sambuc inline void t7() {
176*0a6a1f1dSLionel Sambuc   struct A {};
177*0a6a1f1dSLionel Sambuc   const void *value = &typeid(A*);
178*0a6a1f1dSLionel Sambuc }
t7_helper()179*0a6a1f1dSLionel Sambuc void t7_helper() {
180*0a6a1f1dSLionel Sambuc   t7();
181*0a6a1f1dSLionel Sambuc }
182