rtti-linkage.cpp revision e8f90389c43efbbe820574f674a98ac701bf48a2
1// RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
2#include <typeinfo>
3
4// CHECK: _ZTS1B = constant
5// CHECK: _ZTS1A = weak_odr constant
6// CHECK: _ZTI1A = weak_odr constant
7// CHECK: _ZTI1B = constant
8// CHECK: _ZTSP1C = internal constant
9// CHECK: _ZTS1C = internal constant
10// CHECK: _ZTI1C = internal constant
11// CHECK: _ZTIP1C = internal constant
12// CHECK: _ZTSPP1C = internal constant
13// CHECK: _ZTIPP1C = internal constant
14// CHECK: _ZTSM1Ci = internal constant
15// CHECK: _ZTIM1Ci = internal constant
16// CHECK: _ZTSPM1Ci = internal constant
17// CHECK: _ZTIPM1Ci = internal constant
18// CHECK: _ZTSM1CS_ = internal constant
19// CHECK: _ZTIM1CS_ = internal constant
20// CHECK: _ZTSM1CPS_ = internal constant
21// CHECK: _ZTIM1CPS_ = internal constant
22// CHECK: _ZTSM1A1C = internal constant
23// CHECK: _ZTIM1A1C = internal constant
24// CHECK: _ZTSM1AP1C = internal constant
25// CHECK: _ZTIM1AP1C = internal constant
26
27// CHECK: _ZTS1F = weak_odr constant
28
29// CHECK: _ZTSN12_GLOBAL__N_11DE = internal constant
30// CHECK: _ZTIN12_GLOBAL__N_11DE = internal constant
31// CHECK: _ZTSPN12_GLOBAL__N_11DE = internal constant
32// CHECK: _ZTIPN12_GLOBAL__N_11DE = internal constant
33// CHECK: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
34// CHECK: _ZTIFN12_GLOBAL__N_11DEvE = internal constant
35// CHECK: _ZTSFvN12_GLOBAL__N_11DEE = internal constant
36// CHECK: _ZTIFvN12_GLOBAL__N_11DEE = internal constant
37
38// CHECK: _ZTSPFvvE = weak_odr constant
39// CHECK: _ZTSFvvE = weak_odr constant
40// CHECK: _ZTIFvvE = weak_odr
41// CHECK: _ZTIPFvvE = weak_odr constant
42
43// CHECK: _ZTSN12_GLOBAL__N_11EE = internal constant
44// CHECK: _ZTIN12_GLOBAL__N_11EE = internal constant
45
46// A has no key function, so its RTTI data should be weak_odr.
47struct A { };
48
49// B has a key function defined in the translation unit, so the RTTI data should
50// be emitted in this translation unit and have external linkage.
51struct B : A {
52  virtual void f();
53};
54void B::f() { }
55
56// C is an incomplete class type, so any direct or indirect pointer types should have
57// internal linkage, as should the type info for C itself.
58struct C;
59
60void t1() {
61  (void)typeid(C*);
62  (void)typeid(C**);
63  (void)typeid(int C::*);
64  (void)typeid(int C::**);
65  (void)typeid(C C::*);
66  (void)typeid(C *C::*);
67  (void)typeid(C A::*);
68  (void)typeid(C* A::*);
69}
70
71namespace {
72  // D is inside an anonymous namespace, so all type information related to D should have
73  // internal linkage.
74  struct D { };
75
76  // E is also inside an anonymous namespace.
77  enum E { };
78
79};
80
81// F has a key function defined in the translation unit, but it is inline so the RTTI
82// data should be emitted with weak_odr linkage.
83struct F {
84  virtual void f();
85};
86
87inline void F::f() { }
88const D getD();
89
90const std::type_info &t2() {
91  (void)typeid(const D);
92  (void)typeid(D *);
93  (void)typeid(D (*)());
94  (void)typeid(void (*)(D));
95  // The exception specification is not part of the RTTI descriptor, so it should not have
96  // internal linkage.
97  (void)typeid(void (*)() throw (D));
98
99  (void)typeid(E);
100
101  // CHECK: _ZTIN12_GLOBAL__N_11DE to
102  return typeid(getD());
103}
104