blob: 42fe435234042692124c1a3e88f901203df0c0e2 [file] [log] [blame]
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +00001// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -fhidden-weak-vtables -emit-llvm -o - | FileCheck %s
Argyrios Kyrtzidis6d576052010-10-11 03:25:53 +00002// 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 Dunbarecb2df22010-05-14 03:54:53 +00003
Anders Carlsson8d145152009-12-20 22:30:54 +00004#include <typeinfo>
Anders Carlsson4e713562009-12-11 16:37:06 +00005
Argyrios Kyrtzidis6d576052010-10-11 03:25:53 +00006// CHECK-WITH-HIDDEN: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
Anders Carlsson907c8282011-01-29 22:10:32 +00007// CHECK-WITH-HIDDEN: @_ZTSPK2T4 = linkonce_odr hidden constant
Anders Carlssonf502d932011-01-24 00:46:19 +00008// 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 Gregor6fb745b2010-05-13 16:44:06 +000011
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +000012// CHECK: _ZTSP1C = internal constant
13// CHECK: _ZTS1C = internal constant
Rafael Espindola57244f62011-01-11 23:55:05 +000014// CHECK: _ZTI1C = internal unnamed_addr constant
15// CHECK: _ZTIP1C = internal unnamed_addr constant
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +000016// CHECK: _ZTSPP1C = internal constant
Rafael Espindola57244f62011-01-11 23:55:05 +000017// CHECK: _ZTIPP1C = internal unnamed_addr constant
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +000018// CHECK: _ZTSM1Ci = internal constant
Rafael Espindola57244f62011-01-11 23:55:05 +000019// CHECK: _ZTIM1Ci = internal unnamed_addr constant
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +000020// CHECK: _ZTSPM1Ci = internal constant
Rafael Espindola57244f62011-01-11 23:55:05 +000021// CHECK: _ZTIPM1Ci = internal unnamed_addr constant
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +000022// CHECK: _ZTSM1CS_ = internal constant
Rafael Espindola57244f62011-01-11 23:55:05 +000023// CHECK: _ZTIM1CS_ = internal unnamed_addr constant
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +000024// CHECK: _ZTSM1CPS_ = internal constant
Rafael Espindola57244f62011-01-11 23:55:05 +000025// CHECK: _ZTIM1CPS_ = internal unnamed_addr constant
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +000026// CHECK: _ZTSM1A1C = internal constant
Anders Carlssonf502d932011-01-24 00:46:19 +000027// CHECK: _ZTS1A = linkonce_odr constant
28// CHECK: _ZTI1A = linkonce_odr hidden unnamed_addr constant
Rafael Espindola57244f62011-01-11 23:55:05 +000029// CHECK: _ZTIM1A1C = internal unnamed_addr constant
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +000030// CHECK: _ZTSM1AP1C = internal constant
Rafael Espindola57244f62011-01-11 23:55:05 +000031// CHECK: _ZTIM1AP1C = internal unnamed_addr constant
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +000032// CHECK: _ZTSN12_GLOBAL__N_11DE = internal constant
Rafael Espindola57244f62011-01-11 23:55:05 +000033// CHECK: _ZTIN12_GLOBAL__N_11DE = internal unnamed_addr constant
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +000034// CHECK: _ZTSPN12_GLOBAL__N_11DE = internal constant
Rafael Espindola57244f62011-01-11 23:55:05 +000035// CHECK: _ZTIPN12_GLOBAL__N_11DE = internal unnamed_addr constant
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +000036// CHECK: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
Rafael Espindola57244f62011-01-11 23:55:05 +000037// CHECK: _ZTIFN12_GLOBAL__N_11DEvE = internal unnamed_addr constant
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +000038// CHECK: _ZTSFvN12_GLOBAL__N_11DEE = internal constant
Rafael Espindola57244f62011-01-11 23:55:05 +000039// CHECK: _ZTIFvN12_GLOBAL__N_11DEE = internal unnamed_addr constant
Anders Carlssonf502d932011-01-24 00:46:19 +000040// 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 Takumifd4524b2010-11-08 01:05:10 +000044// CHECK: _ZTSN12_GLOBAL__N_11EE = internal constant
Rafael Espindola57244f62011-01-11 23:55:05 +000045// CHECK: _ZTIN12_GLOBAL__N_11EE = internal unnamed_addr constant
Anders Carlssonf502d932011-01-24 00:46:19 +000046// 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 Espindola57244f62011-01-11 23:55:05 +000049// CHECK: _ZTI1TILj1EE = weak_odr unnamed_addr constant
John McCallcbfe5022010-08-04 08:34:44 +000050// CHECK: _ZTI1TILj2EE = external constant
Douglas Gregor6fb745b2010-05-13 16:44:06 +000051// CHECK: _ZTS1B = constant
Rafael Espindola57244f62011-01-11 23:55:05 +000052// CHECK: _ZTI1B = unnamed_addr constant
Anders Carlssonf502d932011-01-24 00:46:19 +000053// CHECK: _ZTS1F = linkonce_odr constant
NAKAMURA Takumifd4524b2010-11-08 01:05:10 +000054
55// CHECK: _ZTIN12_GLOBAL__N_11DE to
Anders Carlsson9c7b6bb2009-12-29 22:13:01 +000056
Anders Carlssonf502d932011-01-24 00:46:19 +000057// A has no key function, so its RTTI data should be linkonce_odr.
Anders Carlsson4e713562009-12-11 16:37:06 +000058struct 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.
62struct B : A {
63 virtual void f();
64};
65void B::f() { }
Anders Carlsson8d145152009-12-20 22:30:54 +000066
67// C is an incomplete class type, so any direct or indirect pointer types should have
Anders Carlssonf64531a2009-12-30 01:00:12 +000068// internal linkage, as should the type info for C itself.
Anders Carlsson8d145152009-12-20 22:30:54 +000069struct C;
70
Anders Carlsson610b0d92009-12-21 00:57:38 +000071void t1() {
Anders Carlsson8d145152009-12-20 22:30:54 +000072 (void)typeid(C*);
73 (void)typeid(C**);
Anders Carlsson17fa6f92009-12-20 23:37:55 +000074 (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 Carlsson8d145152009-12-20 22:30:54 +000080}
81
Anders Carlsson610b0d92009-12-21 00:57:38 +000082namespace {
83 // D is inside an anonymous namespace, so all type information related to D should have
84 // internal linkage.
85 struct D { };
Anders Carlsson9c7b6bb2009-12-29 22:13:01 +000086
87 // E is also inside an anonymous namespace.
88 enum E { };
89
Anders Carlsson610b0d92009-12-21 00:57:38 +000090};
91
Anders Carlssone8f90382009-12-31 19:36:25 +000092// F has a key function defined in the translation unit, but it is inline so the RTTI
Anders Carlssonf502d932011-01-24 00:46:19 +000093// data should be emitted with linkonce_odr linkage.
Anders Carlssone8f90382009-12-31 19:36:25 +000094struct F {
95 virtual void f();
96};
97
98inline void F::f() { }
Douglas Gregorf57f2072009-12-23 20:51:04 +000099const D getD();
100
101const std::type_info &t2() {
102 (void)typeid(const D);
Anders Carlsson09b6e6e2009-12-29 20:20:19 +0000103 (void)typeid(D *);
104 (void)typeid(D (*)());
105 (void)typeid(void (*)(D));
Douglas Gregor031b3712010-03-31 00:15:35 +0000106 (void)typeid(void (*)(D&));
Anders Carlsson09b6e6e2009-12-29 20:20:19 +0000107 // 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 Carlsson9c7b6bb2009-12-29 22:13:01 +0000111 (void)typeid(E);
112
Douglas Gregorf57f2072009-12-23 20:51:04 +0000113 return typeid(getD());
Anders Carlsson610b0d92009-12-21 00:57:38 +0000114}
Douglas Gregord1c1d7b2010-06-02 06:16:02 +0000115
116namespace 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 McCallcbfe5022010-08-04 08:34:44 +0000124
125template <unsigned N> class T {
126 virtual void anchor() {}
127};
128template class T<1>;
129template <> class T<2> { virtual void anchor(); };
130void t3() {
131 (void) typeid(T<0>);
132 (void) typeid(T<1>);
133 (void) typeid(T<2>);
134}
John McCall9c39acf2010-12-17 02:58:03 +0000135
136// rdar://problem/8778973
137struct T4 {};
138void t4(const T4 *ptr) {
139 const void *value = &typeid(ptr);
140}