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