NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fhidden-weak-vtables -emit-llvm -o - | FileCheck %s |
Argyrios Kyrtzidis | 6d57605 | 2010-10-11 03:25:53 +0000 | [diff] [blame] | 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 |
Daniel Dunbar | ecb2df2 | 2010-05-14 03:54:53 +0000 | [diff] [blame] | 3 | |
Anders Carlsson | 8d14515 | 2009-12-20 22:30:54 +0000 | [diff] [blame] | 4 | #include <typeinfo> |
Anders Carlsson | 4e71356 | 2009-12-11 16:37:06 +0000 | [diff] [blame] | 5 | |
Argyrios Kyrtzidis | 6d57605 | 2010-10-11 03:25:53 +0000 | [diff] [blame] | 6 | // CHECK-WITH-HIDDEN: _ZTSFN12_GLOBAL__N_11DEvE = internal constant |
Anders Carlsson | 907c828 | 2011-01-29 22:10:32 +0000 | [diff] [blame] | 7 | // CHECK-WITH-HIDDEN: @_ZTSPK2T4 = linkonce_odr hidden constant |
Anders Carlsson | f502d93 | 2011-01-24 00:46:19 +0000 | [diff] [blame] | 8 | // CHECK-WITH-HIDDEN: @_ZTS2T4 = linkonce_odr hidden constant |
| 9 | // CHECK-WITH-HIDDEN: @_ZTI2T4 = linkonce_odr hidden unnamed_addr constant |
| 10 | // CHECK-WITH-HIDDEN: @_ZTIPK2T4 = linkonce_odr hidden unnamed_addr constant |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 11 | |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 12 | // CHECK: _ZTSP1C = internal constant |
| 13 | // CHECK: _ZTS1C = internal constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 14 | // CHECK: _ZTI1C = internal unnamed_addr constant |
| 15 | // CHECK: _ZTIP1C = internal unnamed_addr constant |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 16 | // CHECK: _ZTSPP1C = internal constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 17 | // CHECK: _ZTIPP1C = internal unnamed_addr constant |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 18 | // CHECK: _ZTSM1Ci = internal constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 19 | // CHECK: _ZTIM1Ci = internal unnamed_addr constant |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 20 | // CHECK: _ZTSPM1Ci = internal constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 21 | // CHECK: _ZTIPM1Ci = internal unnamed_addr constant |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 22 | // CHECK: _ZTSM1CS_ = internal constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 23 | // CHECK: _ZTIM1CS_ = internal unnamed_addr constant |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 24 | // CHECK: _ZTSM1CPS_ = internal constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 25 | // CHECK: _ZTIM1CPS_ = internal unnamed_addr constant |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 26 | // CHECK: _ZTSM1A1C = internal constant |
Anders Carlsson | f502d93 | 2011-01-24 00:46:19 +0000 | [diff] [blame] | 27 | // CHECK: _ZTS1A = linkonce_odr constant |
| 28 | // CHECK: _ZTI1A = linkonce_odr hidden unnamed_addr constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 29 | // CHECK: _ZTIM1A1C = internal unnamed_addr constant |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 30 | // CHECK: _ZTSM1AP1C = internal constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 31 | // CHECK: _ZTIM1AP1C = internal unnamed_addr constant |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 32 | // CHECK: _ZTSN12_GLOBAL__N_11DE = internal constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 33 | // CHECK: _ZTIN12_GLOBAL__N_11DE = internal unnamed_addr constant |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 34 | // CHECK: _ZTSPN12_GLOBAL__N_11DE = internal constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 35 | // CHECK: _ZTIPN12_GLOBAL__N_11DE = internal unnamed_addr constant |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 36 | // CHECK: _ZTSFN12_GLOBAL__N_11DEvE = internal constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 37 | // CHECK: _ZTIFN12_GLOBAL__N_11DEvE = internal unnamed_addr constant |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 38 | // CHECK: _ZTSFvN12_GLOBAL__N_11DEE = internal constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 39 | // CHECK: _ZTIFvN12_GLOBAL__N_11DEE = internal unnamed_addr constant |
Anders Carlsson | f502d93 | 2011-01-24 00:46:19 +0000 | [diff] [blame] | 40 | // CHECK: _ZTSPFvvE = linkonce_odr constant |
| 41 | // CHECK: _ZTSFvvE = linkonce_odr constant |
| 42 | // CHECK: _ZTIFvvE = linkonce_odr hidden unnamed_addr constant |
| 43 | // CHECK: _ZTIPFvvE = linkonce_odr hidden unnamed_addr constant |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 44 | // CHECK: _ZTSN12_GLOBAL__N_11EE = internal constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 45 | // CHECK: _ZTIN12_GLOBAL__N_11EE = internal unnamed_addr constant |
Anders Carlsson | f502d93 | 2011-01-24 00:46:19 +0000 | [diff] [blame] | 46 | // CHECK: _ZTSA10_i = linkonce_odr constant |
| 47 | // CHECK: _ZTIA10_i = linkonce_odr hidden unnamed_addr constant |
| 48 | // CHECK: _ZTI1TILj0EE = linkonce_odr unnamed_addr constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 49 | // CHECK: _ZTI1TILj1EE = weak_odr unnamed_addr constant |
John McCall | cbfe502 | 2010-08-04 08:34:44 +0000 | [diff] [blame] | 50 | // CHECK: _ZTI1TILj2EE = external constant |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame] | 51 | // CHECK: _ZTS1B = constant |
Rafael Espindola | 57244f6 | 2011-01-11 23:55:05 +0000 | [diff] [blame] | 52 | // CHECK: _ZTI1B = unnamed_addr constant |
Anders Carlsson | f502d93 | 2011-01-24 00:46:19 +0000 | [diff] [blame] | 53 | // CHECK: _ZTS1F = linkonce_odr constant |
NAKAMURA Takumi | fd4524b | 2010-11-08 01:05:10 +0000 | [diff] [blame] | 54 | |
| 55 | // CHECK: _ZTIN12_GLOBAL__N_11DE to |
Anders Carlsson | 9c7b6bb | 2009-12-29 22:13:01 +0000 | [diff] [blame] | 56 | |
Anders Carlsson | f502d93 | 2011-01-24 00:46:19 +0000 | [diff] [blame] | 57 | // A has no key function, so its RTTI data should be linkonce_odr. |
Anders Carlsson | 4e71356 | 2009-12-11 16:37:06 +0000 | [diff] [blame] | 58 | struct 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. |
| 62 | struct B : A { |
| 63 | virtual void f(); |
| 64 | }; |
| 65 | void B::f() { } |
Anders Carlsson | 8d14515 | 2009-12-20 22:30:54 +0000 | [diff] [blame] | 66 | |
| 67 | // C is an incomplete class type, so any direct or indirect pointer types should have |
Anders Carlsson | f64531a | 2009-12-30 01:00:12 +0000 | [diff] [blame] | 68 | // internal linkage, as should the type info for C itself. |
Anders Carlsson | 8d14515 | 2009-12-20 22:30:54 +0000 | [diff] [blame] | 69 | struct C; |
| 70 | |
Anders Carlsson | 610b0d9 | 2009-12-21 00:57:38 +0000 | [diff] [blame] | 71 | void t1() { |
Anders Carlsson | 8d14515 | 2009-12-20 22:30:54 +0000 | [diff] [blame] | 72 | (void)typeid(C*); |
| 73 | (void)typeid(C**); |
Anders Carlsson | 17fa6f9 | 2009-12-20 23:37:55 +0000 | [diff] [blame] | 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::*); |
Anders Carlsson | 8d14515 | 2009-12-20 22:30:54 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Anders Carlsson | 610b0d9 | 2009-12-21 00:57:38 +0000 | [diff] [blame] | 82 | namespace { |
| 83 | // D is inside an anonymous namespace, so all type information related to D should have |
| 84 | // internal linkage. |
| 85 | struct D { }; |
Anders Carlsson | 9c7b6bb | 2009-12-29 22:13:01 +0000 | [diff] [blame] | 86 | |
| 87 | // E is also inside an anonymous namespace. |
| 88 | enum E { }; |
| 89 | |
Anders Carlsson | 610b0d9 | 2009-12-21 00:57:38 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
Anders Carlsson | e8f9038 | 2009-12-31 19:36:25 +0000 | [diff] [blame] | 92 | // F has a key function defined in the translation unit, but it is inline so the RTTI |
Anders Carlsson | f502d93 | 2011-01-24 00:46:19 +0000 | [diff] [blame] | 93 | // data should be emitted with linkonce_odr linkage. |
Anders Carlsson | e8f9038 | 2009-12-31 19:36:25 +0000 | [diff] [blame] | 94 | struct F { |
| 95 | virtual void f(); |
| 96 | }; |
| 97 | |
| 98 | inline void F::f() { } |
Douglas Gregor | f57f207 | 2009-12-23 20:51:04 +0000 | [diff] [blame] | 99 | const D getD(); |
| 100 | |
| 101 | const std::type_info &t2() { |
| 102 | (void)typeid(const D); |
Anders Carlsson | 09b6e6e | 2009-12-29 20:20:19 +0000 | [diff] [blame] | 103 | (void)typeid(D *); |
| 104 | (void)typeid(D (*)()); |
| 105 | (void)typeid(void (*)(D)); |
Douglas Gregor | 031b371 | 2010-03-31 00:15:35 +0000 | [diff] [blame] | 106 | (void)typeid(void (*)(D&)); |
Anders Carlsson | 09b6e6e | 2009-12-29 20:20:19 +0000 | [diff] [blame] | 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 | |
Anders Carlsson | 9c7b6bb | 2009-12-29 22:13:01 +0000 | [diff] [blame] | 111 | (void)typeid(E); |
| 112 | |
Douglas Gregor | f57f207 | 2009-12-23 20:51:04 +0000 | [diff] [blame] | 113 | return typeid(getD()); |
Anders Carlsson | 610b0d9 | 2009-12-21 00:57:38 +0000 | [diff] [blame] | 114 | } |
Douglas Gregor | d1c1d7b | 2010-06-02 06:16:02 +0000 | [diff] [blame] | 115 | |
| 116 | namespace Arrays { |
| 117 | struct A { |
| 118 | static const int a[10]; |
| 119 | }; |
| 120 | const std::type_info &f() { |
| 121 | return typeid(A::a); |
| 122 | } |
| 123 | } |
John McCall | cbfe502 | 2010-08-04 08:34:44 +0000 | [diff] [blame] | 124 | |
| 125 | template <unsigned N> class T { |
| 126 | virtual void anchor() {} |
| 127 | }; |
| 128 | template class T<1>; |
| 129 | template <> class T<2> { virtual void anchor(); }; |
| 130 | void t3() { |
| 131 | (void) typeid(T<0>); |
| 132 | (void) typeid(T<1>); |
| 133 | (void) typeid(T<2>); |
| 134 | } |
John McCall | 9c39acf | 2010-12-17 02:58:03 +0000 | [diff] [blame] | 135 | |
| 136 | // rdar://problem/8778973 |
| 137 | struct T4 {}; |
| 138 | void t4(const T4 *ptr) { |
| 139 | const void *value = &typeid(ptr); |
| 140 | } |