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