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