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