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