180 lines · cpp
1// RUN: %clang_cc1 %std_cxx98- %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -Wno-dynamic-exception-spec -o - | FileCheck %s -check-prefixes=CHECK,CHECK-BOTH2// RUN: %clang_cc1 %std_cxx98- %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -Wno-dynamic-exception-spec -fvisibility=hidden -o - | FileCheck %s --check-prefixes=CHECK-WITH-HIDDEN,CHECK-BOTH3 4#include <typeinfo>5 6// CHECK-BOTH: _ZTIP1C = internal constant7// CHECK-BOTH: _ZTSP1C = internal constant8// CHECK-BOTH: _ZTI1C = internal constant9// CHECK-BOTH: _ZTS1C = internal constant10// CHECK-BOTH: _ZTIPP1C = internal constant11// CHECK-BOTH: _ZTSPP1C = internal constant12// CHECK-BOTH: _ZTIM1Ci = internal constant13// CHECK-BOTH: _ZTSM1Ci = internal constant14// CHECK-BOTH: _ZTIPM1Ci = internal constant15// CHECK-BOTH: _ZTSPM1Ci = internal constant16// CHECK-BOTH: _ZTIM1CS_ = internal constant17// CHECK-BOTH: _ZTSM1CS_ = internal constant18// CHECK-BOTH: _ZTIM1CPS_ = internal constant19// CHECK-BOTH: _ZTSM1CPS_ = internal constant20// CHECK-BOTH: _ZTIM1A1C = internal constant21// CHECK-BOTH: _ZTSM1A1C = internal constant22// CHECK: _ZTI1A = linkonce_odr constant23// CHECK-WITH-HIDDEN: _ZTI1A = linkonce_odr hidden constant24// CHECK: _ZTS1A = linkonce_odr constant25// CHECK-WITH-HIDDEN: _ZTS1A = linkonce_odr hidden constant26// CHECK-BOTH: _ZTIM1AP1C = internal constant27// CHECK-BOTH: _ZTSM1AP1C = internal constant28 29// CHECK-WITH-HIDDEN: _ZTSFN12_GLOBAL__N_11DEvE = internal constant30// CHECK-WITH-HIDDEN: @_ZTIPK2T4 = linkonce_odr hidden constant31// CHECK-WITH-HIDDEN: @_ZTSPK2T4 = linkonce_odr hidden constant32// CHECK-WITH-HIDDEN: @_ZTI2T4 = linkonce_odr hidden constant33// CHECK-WITH-HIDDEN: @_ZTS2T4 = linkonce_odr hidden constant34// CHECK-WITH-HIDDEN: @_ZTIZ2t5vE1A = internal constant35// CHECK-WITH-HIDDEN: @_ZTSZ2t5vE1A = internal constant36// CHECK-WITH-HIDDEN: @_ZTIZ2t6vE1A = linkonce_odr hidden constant37// CHECK-WITH-HIDDEN: @_ZTSZ2t6vE1A = linkonce_odr hidden constant38// CHECK-WITH-HIDDEN: @_ZTIPZ2t7vE1A = linkonce_odr hidden constant39// CHECK-WITH-HIDDEN: @_ZTSPZ2t7vE1A = linkonce_odr hidden constant40// CHECK-WITH-HIDDEN: @_ZTIZ2t7vE1A = linkonce_odr hidden constant41// CHECK-WITH-HIDDEN: @_ZTSZ2t7vE1A = linkonce_odr hidden constant42 43// CHECK: _ZTIN12_GLOBAL__N_11DE = internal constant44// CHECK: _ZTSN12_GLOBAL__N_11DE = internal constant45// CHECK: _ZTIPN12_GLOBAL__N_11DE = internal constant46// CHECK: _ZTSPN12_GLOBAL__N_11DE = internal constant47// CHECK: _ZTIFN12_GLOBAL__N_11DEvE = internal constant48// CHECK: _ZTSFN12_GLOBAL__N_11DEvE = internal constant49// CHECK: _ZTIFvN12_GLOBAL__N_11DEE = internal constant50// CHECK: _ZTSFvN12_GLOBAL__N_11DEE = internal constant51// CHECK: _ZTIPFvvE = linkonce_odr constant52// CHECK: _ZTSPFvvE = linkonce_odr constant53// CHECK: _ZTIFvvE = linkonce_odr constant54// CHECK: _ZTSFvvE = linkonce_odr constant55// CHECK: _ZTIN12_GLOBAL__N_11EE = internal constant56// CHECK: _ZTSN12_GLOBAL__N_11EE = internal constant57// CHECK: _ZTIA10_i = linkonce_odr constant58// CHECK: _ZTSA10_i = linkonce_odr constant59// CHECK: _ZTI1TILj0EE = linkonce_odr constant60// CHECK: _ZTI1TILj1EE = weak_odr constant61// CHECK: _ZTI1TILj2EE = external constant62// CHECK: _ZTIZ2t5vE1A = internal constant63// CHECK: _ZTSZ2t5vE1A = internal constant64// CHECK: _ZTI1B ={{.*}} constant65// CHECK: _ZTS1B ={{.*}} constant66// CHECK: _ZTS1F = linkonce_odr constant67// CHECK: _ZTIZ2t6vE1A = linkonce_odr constant68// CHECK: _ZTSZ2t6vE1A = linkonce_odr constant69// CHECK: _ZTIPZ2t7vE1A = linkonce_odr constant70// CHECK: _ZTSPZ2t7vE1A = linkonce_odr constant71// CHECK: _ZTIZ2t7vE1A = linkonce_odr constant72// CHECK: _ZTSZ2t7vE1A = linkonce_odr constant73 74// CHECK: _ZTIN12_GLOBAL__N_11DE75 76// A has no key function, so its RTTI data should be linkonce_odr.77struct A { };78 79// B has a key function defined in the translation unit, so the RTTI data should80// be emitted in this translation unit and have external linkage.81struct B : A {82 virtual void f();83};84void 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.88struct C;89 90void 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 101namespace {102 // D is inside an anonymous namespace, so all type information related to D should have103 // 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 RTTI112// data should be emitted with linkonce_odr linkage.113struct F {114 virtual void f();115};116 117inline void F::f() { }118const D getD();119 120const 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 have127 // internal linkage.128 (void)typeid(void (*)() throw (D));129 130 (void)typeid(E);131 132 return typeid(getD()); 133}134 135namespace 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 144template <unsigned N> class T {145 virtual void anchor() {}146};147template class T<1>;148template <> class T<2> { virtual void anchor(); };149void t3() {150 (void) typeid(T<0>);151 (void) typeid(T<1>);152 (void) typeid(T<2>);153}154 155struct T4 {};156void t4(const T4 *ptr) {157 const void *value = &typeid(ptr);158}159 160void t5() {161 struct A {};162 const void *value = &typeid(A);163}164 165inline void t6() {166 struct A {};167 const void *value = &typeid(A);168}169void t6_helper() {170 t6();171}172 173inline void t7() {174 struct A {};175 const void *value = &typeid(A*);176}177void t7_helper() {178 t7();179}180