16bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BOTH 26bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// 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 3ecb2df2408639e554def61080ce3afdb41e2f705Daniel Dunbar 48d1451535524cb21a6f8347bad9fed371b9d9ecbAnders Carlsson#include <typeinfo> 54e7135613a558020f003972b2a5ae5f8d5306508Anders Carlsson 66bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTSP1C = internal constant 76bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTS1C = internal constant 86bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTI1C = internal constant 96bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTIP1C = internal constant 106bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTSPP1C = internal constant 116bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTIPP1C = internal constant 126bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTSM1Ci = internal constant 136bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTIM1Ci = internal constant 146bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTSPM1Ci = internal constant 156bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTIPM1Ci = internal constant 166bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTSM1CS_ = internal constant 176bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTIM1CS_ = internal constant 186bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTSM1CPS_ = internal constant 196bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTIM1CPS_ = internal constant 206bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTSM1A1C = internal constant 216bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: _ZTS1A = linkonce_odr constant 226bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-WITH-HIDDEN: _ZTS1A = linkonce_odr hidden constant 236bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK: _ZTI1A = linkonce_odr constant 246bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-WITH-HIDDEN: _ZTI1A = linkonce_odr hidden constant 256bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTIM1A1C = internal constant 266bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTSM1AP1C = internal constant 276bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines// CHECK-BOTH: _ZTIM1AP1C = internal constant 286bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines 296d576051b9ca56fe962077fb194ed2917539989aArgyrios Kyrtzidis// CHECK-WITH-HIDDEN: _ZTSFN12_GLOBAL__N_11DEvE = internal constant 30907c828b080332854826a87451e838930f4be788Anders Carlsson// CHECK-WITH-HIDDEN: @_ZTSPK2T4 = linkonce_odr hidden constant 31f502d93b0ea970bfbd897e657f8d940a20984de2Anders Carlsson// CHECK-WITH-HIDDEN: @_ZTS2T4 = linkonce_odr hidden constant 32651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK-WITH-HIDDEN: @_ZTI2T4 = linkonce_odr hidden constant 33651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK-WITH-HIDDEN: @_ZTIPK2T4 = linkonce_odr hidden constant 34651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK-WITH-HIDDEN: @_ZTSZ2t5vE1A = internal constant 35651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK-WITH-HIDDEN: @_ZTIZ2t5vE1A = internal constant 360e2c34f92f00628d48968dfea096d36381f494cbStephen Hines// CHECK-WITH-HIDDEN: @_ZTSZ2t6vE1A = linkonce_odr hidden constant 370e2c34f92f00628d48968dfea096d36381f494cbStephen Hines// CHECK-WITH-HIDDEN: @_ZTIZ2t6vE1A = linkonce_odr hidden constant 38651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK-WITH-HIDDEN: @_ZTSPZ2t7vE1A = linkonce_odr hidden constant 39651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK-WITH-HIDDEN: @_ZTSZ2t7vE1A = linkonce_odr hidden constant 40651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK-WITH-HIDDEN: @_ZTIZ2t7vE1A = linkonce_odr hidden constant 41651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK-WITH-HIDDEN: @_ZTIPZ2t7vE1A = linkonce_odr hidden constant 426fb745bdf1ff1e32caf07e42093a7920726892c1Douglas Gregor 43fd4524b4452d5dcda9c7cb9b1b665fd0f4b6267eNAKAMURA Takumi// CHECK: _ZTSN12_GLOBAL__N_11DE = internal constant 44651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTIN12_GLOBAL__N_11DE = internal constant 45fd4524b4452d5dcda9c7cb9b1b665fd0f4b6267eNAKAMURA Takumi// CHECK: _ZTSPN12_GLOBAL__N_11DE = internal constant 46651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTIPN12_GLOBAL__N_11DE = internal constant 4709b6e6e8854cc4a824060101a9633082e55d7a33Anders Carlsson// CHECK: _ZTSFN12_GLOBAL__N_11DEvE = internal constant 48651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTIFN12_GLOBAL__N_11DEvE = internal constant 4909b6e6e8854cc4a824060101a9633082e55d7a33Anders Carlsson// CHECK: _ZTSFvN12_GLOBAL__N_11DEE = internal constant 50651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTIFvN12_GLOBAL__N_11DEE = internal constant 51f502d93b0ea970bfbd897e657f8d940a20984de2Anders Carlsson// CHECK: _ZTSPFvvE = linkonce_odr constant 52f502d93b0ea970bfbd897e657f8d940a20984de2Anders Carlsson// CHECK: _ZTSFvvE = linkonce_odr constant 53651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTIFvvE = linkonce_odr constant 54651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTIPFvvE = linkonce_odr constant 559c7b6bb952672b9d184a4426138579d55c370afcAnders Carlsson// CHECK: _ZTSN12_GLOBAL__N_11EE = internal constant 56651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTIN12_GLOBAL__N_11EE = internal constant 57f502d93b0ea970bfbd897e657f8d940a20984de2Anders Carlsson// CHECK: _ZTSA10_i = linkonce_odr constant 58651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTIA10_i = linkonce_odr constant 59651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTI1TILj0EE = linkonce_odr constant 60651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTI1TILj1EE = weak_odr constant 61fd4524b4452d5dcda9c7cb9b1b665fd0f4b6267eNAKAMURA Takumi// CHECK: _ZTI1TILj2EE = external constant 62651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTSZ2t5vE1A = internal constant 63651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTIZ2t5vE1A = internal constant 64fd4524b4452d5dcda9c7cb9b1b665fd0f4b6267eNAKAMURA Takumi// CHECK: _ZTS1B = constant 65651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTI1B = constant 66f502d93b0ea970bfbd897e657f8d940a20984de2Anders Carlsson// CHECK: _ZTS1F = linkonce_odr constant 670e2c34f92f00628d48968dfea096d36381f494cbStephen Hines// CHECK: _ZTSZ2t6vE1A = linkonce_odr constant 680e2c34f92f00628d48968dfea096d36381f494cbStephen Hines// CHECK: _ZTIZ2t6vE1A = linkonce_odr constant 69651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTSPZ2t7vE1A = linkonce_odr constant 70651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTSZ2t7vE1A = linkonce_odr constant 71651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTIZ2t7vE1A = linkonce_odr constant 72651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// CHECK: _ZTIPZ2t7vE1A = linkonce_odr constant 73fd4524b4452d5dcda9c7cb9b1b665fd0f4b6267eNAKAMURA Takumi 74fd4524b4452d5dcda9c7cb9b1b665fd0f4b6267eNAKAMURA Takumi// CHECK: _ZTIN12_GLOBAL__N_11DE to 759c7b6bb952672b9d184a4426138579d55c370afcAnders Carlsson 76f502d93b0ea970bfbd897e657f8d940a20984de2Anders Carlsson// A has no key function, so its RTTI data should be linkonce_odr. 774e7135613a558020f003972b2a5ae5f8d5306508Anders Carlssonstruct A { }; 784e7135613a558020f003972b2a5ae5f8d5306508Anders Carlsson 794e7135613a558020f003972b2a5ae5f8d5306508Anders Carlsson// B has a key function defined in the translation unit, so the RTTI data should 804e7135613a558020f003972b2a5ae5f8d5306508Anders Carlsson// be emitted in this translation unit and have external linkage. 814e7135613a558020f003972b2a5ae5f8d5306508Anders Carlssonstruct B : A { 824e7135613a558020f003972b2a5ae5f8d5306508Anders Carlsson virtual void f(); 834e7135613a558020f003972b2a5ae5f8d5306508Anders Carlsson}; 844e7135613a558020f003972b2a5ae5f8d5306508Anders Carlssonvoid B::f() { } 858d1451535524cb21a6f8347bad9fed371b9d9ecbAnders Carlsson 868d1451535524cb21a6f8347bad9fed371b9d9ecbAnders Carlsson// C is an incomplete class type, so any direct or indirect pointer types should have 87f64531a17037faa9e0119e90961d2db77d06865dAnders Carlsson// internal linkage, as should the type info for C itself. 888d1451535524cb21a6f8347bad9fed371b9d9ecbAnders Carlssonstruct C; 898d1451535524cb21a6f8347bad9fed371b9d9ecbAnders Carlsson 90610b0d94d71810773378be4f39922a56b1202a83Anders Carlssonvoid t1() { 918d1451535524cb21a6f8347bad9fed371b9d9ecbAnders Carlsson (void)typeid(C*); 928d1451535524cb21a6f8347bad9fed371b9d9ecbAnders Carlsson (void)typeid(C**); 9317fa6f971c1912c77aa10bdac4b7991b5e1646e2Anders Carlsson (void)typeid(int C::*); 9417fa6f971c1912c77aa10bdac4b7991b5e1646e2Anders Carlsson (void)typeid(int C::**); 9517fa6f971c1912c77aa10bdac4b7991b5e1646e2Anders Carlsson (void)typeid(C C::*); 9617fa6f971c1912c77aa10bdac4b7991b5e1646e2Anders Carlsson (void)typeid(C *C::*); 9717fa6f971c1912c77aa10bdac4b7991b5e1646e2Anders Carlsson (void)typeid(C A::*); 9817fa6f971c1912c77aa10bdac4b7991b5e1646e2Anders Carlsson (void)typeid(C* A::*); 998d1451535524cb21a6f8347bad9fed371b9d9ecbAnders Carlsson} 1008d1451535524cb21a6f8347bad9fed371b9d9ecbAnders Carlsson 101610b0d94d71810773378be4f39922a56b1202a83Anders Carlssonnamespace { 102610b0d94d71810773378be4f39922a56b1202a83Anders Carlsson // D is inside an anonymous namespace, so all type information related to D should have 103610b0d94d71810773378be4f39922a56b1202a83Anders Carlsson // internal linkage. 104610b0d94d71810773378be4f39922a56b1202a83Anders Carlsson struct D { }; 1059c7b6bb952672b9d184a4426138579d55c370afcAnders Carlsson 1069c7b6bb952672b9d184a4426138579d55c370afcAnders Carlsson // E is also inside an anonymous namespace. 1079c7b6bb952672b9d184a4426138579d55c370afcAnders Carlsson enum E { }; 1089c7b6bb952672b9d184a4426138579d55c370afcAnders Carlsson 109610b0d94d71810773378be4f39922a56b1202a83Anders Carlsson}; 110610b0d94d71810773378be4f39922a56b1202a83Anders Carlsson 111e8f90389c43efbbe820574f674a98ac701bf48a2Anders Carlsson// F has a key function defined in the translation unit, but it is inline so the RTTI 112f502d93b0ea970bfbd897e657f8d940a20984de2Anders Carlsson// data should be emitted with linkonce_odr linkage. 113e8f90389c43efbbe820574f674a98ac701bf48a2Anders Carlssonstruct F { 114e8f90389c43efbbe820574f674a98ac701bf48a2Anders Carlsson virtual void f(); 115e8f90389c43efbbe820574f674a98ac701bf48a2Anders Carlsson}; 116e8f90389c43efbbe820574f674a98ac701bf48a2Anders Carlsson 117e8f90389c43efbbe820574f674a98ac701bf48a2Anders Carlssoninline void F::f() { } 118f57f207a0fcf5fb7883597b57dd03faf952318ddDouglas Gregorconst D getD(); 119f57f207a0fcf5fb7883597b57dd03faf952318ddDouglas Gregor 120f57f207a0fcf5fb7883597b57dd03faf952318ddDouglas Gregorconst std::type_info &t2() { 121f57f207a0fcf5fb7883597b57dd03faf952318ddDouglas Gregor (void)typeid(const D); 12209b6e6e8854cc4a824060101a9633082e55d7a33Anders Carlsson (void)typeid(D *); 12309b6e6e8854cc4a824060101a9633082e55d7a33Anders Carlsson (void)typeid(D (*)()); 12409b6e6e8854cc4a824060101a9633082e55d7a33Anders Carlsson (void)typeid(void (*)(D)); 125031b37140d0864c741618960b5220245a2a086aeDouglas Gregor (void)typeid(void (*)(D&)); 12609b6e6e8854cc4a824060101a9633082e55d7a33Anders Carlsson // The exception specification is not part of the RTTI descriptor, so it should not have 12709b6e6e8854cc4a824060101a9633082e55d7a33Anders Carlsson // internal linkage. 12809b6e6e8854cc4a824060101a9633082e55d7a33Anders Carlsson (void)typeid(void (*)() throw (D)); 12909b6e6e8854cc4a824060101a9633082e55d7a33Anders Carlsson 1309c7b6bb952672b9d184a4426138579d55c370afcAnders Carlsson (void)typeid(E); 1319c7b6bb952672b9d184a4426138579d55c370afcAnders Carlsson 132f57f207a0fcf5fb7883597b57dd03faf952318ddDouglas Gregor return typeid(getD()); 133610b0d94d71810773378be4f39922a56b1202a83Anders Carlsson} 134d1c1d7bd14dce533e8755164ff59988f2ea5da94Douglas Gregor 135d1c1d7bd14dce533e8755164ff59988f2ea5da94Douglas Gregornamespace Arrays { 136d1c1d7bd14dce533e8755164ff59988f2ea5da94Douglas Gregor struct A { 137d1c1d7bd14dce533e8755164ff59988f2ea5da94Douglas Gregor static const int a[10]; 138d1c1d7bd14dce533e8755164ff59988f2ea5da94Douglas Gregor }; 139d1c1d7bd14dce533e8755164ff59988f2ea5da94Douglas Gregor const std::type_info &f() { 140d1c1d7bd14dce533e8755164ff59988f2ea5da94Douglas Gregor return typeid(A::a); 141d1c1d7bd14dce533e8755164ff59988f2ea5da94Douglas Gregor } 142d1c1d7bd14dce533e8755164ff59988f2ea5da94Douglas Gregor} 143cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall 144cbfe50224b19119e759802bd0c1463269dffd09eJohn McCalltemplate <unsigned N> class T { 145cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall virtual void anchor() {} 146cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall}; 147cbfe50224b19119e759802bd0c1463269dffd09eJohn McCalltemplate class T<1>; 148cbfe50224b19119e759802bd0c1463269dffd09eJohn McCalltemplate <> class T<2> { virtual void anchor(); }; 149cbfe50224b19119e759802bd0c1463269dffd09eJohn McCallvoid t3() { 150cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall (void) typeid(T<0>); 151cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall (void) typeid(T<1>); 152cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall (void) typeid(T<2>); 153cbfe50224b19119e759802bd0c1463269dffd09eJohn McCall} 1549c39acfda88268bcc7fb5521b55ce41942dcb3b0John McCall 1559c39acfda88268bcc7fb5521b55ce41942dcb3b0John McCall// rdar://problem/8778973 1569c39acfda88268bcc7fb5521b55ce41942dcb3b0John McCallstruct T4 {}; 1579c39acfda88268bcc7fb5521b55ce41942dcb3b0John McCallvoid t4(const T4 *ptr) { 1589c39acfda88268bcc7fb5521b55ce41942dcb3b0John McCall const void *value = &typeid(ptr); 1599c39acfda88268bcc7fb5521b55ce41942dcb3b0John McCall} 160651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 161651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines// rdar://16265084 162651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid t5() { 163651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines struct A {}; 164651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const void *value = &typeid(A); 165651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 166651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 167651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesinline void t6() { 168651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines struct A {}; 169651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const void *value = &typeid(A); 170651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 171651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid t6_helper() { 172651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines t6(); 173651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 174651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines 175651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesinline void t7() { 176651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines struct A {}; 177651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines const void *value = &typeid(A*); 178651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 179651f13cea278ec967336033dd032faef0e9fc2ecStephen Hinesvoid t7_helper() { 180651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines t7(); 181651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines} 182