rtti-linkage.cpp revision 9c7b6bb952672b9d184a4426138579d55c370afc
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: _ZTSN12_GLOBAL__N_11DE = internal constant
28// CHECK: _ZTIN12_GLOBAL__N_11DE = internal constant
29// CHECK: _ZTSPN12_GLOBAL__N_11DE = internal constant
30// CHECK: _ZTIPN12_GLOBAL__N_11DE = internal constant
31// CHECK: _ZTSFN12_GLOBAL__N_11DEvE = internal constant
32// CHECK: _ZTIFN12_GLOBAL__N_11DEvE = internal constant
33// CHECK: _ZTSFvN12_GLOBAL__N_11DEE = internal constant
34// CHECK: _ZTIFvN12_GLOBAL__N_11DEE = internal constant
35
36// CHECK: _ZTSPFvvE = weak_odr constant
37// CHECK: _ZTSFvvE = weak_odr constant
38// CHECK: _ZTIFvvE = weak_odr
39// CHECK: _ZTIPFvvE = weak_odr constant
40
41// CHECK: _ZTSN12_GLOBAL__N_11EE = internal constant
42// CHECK: _ZTIN12_GLOBAL__N_11EE = internal constant
43
44// A has no key function, so its RTTI data should be weak_odr.
45struct A { };
46
47// B has a key function defined in the translation unit, so the RTTI data should
48// be emitted in this translation unit and have external linkage.
49struct B : A {
50  virtual void f();
51};
52void B::f() { }
53
54// C is an incomplete class type, so any direct or indirect pointer types should have
55// internal linkage, as should the type info for C itself (FIXME).
56struct C;
57
58void t1() {
59  (void)typeid(C*);
60  (void)typeid(C**);
61  (void)typeid(int C::*);
62  (void)typeid(int C::**);
63  (void)typeid(C C::*);
64  (void)typeid(C *C::*);
65  (void)typeid(C A::*);
66  (void)typeid(C* A::*);
67}
68
69namespace {
70  // D is inside an anonymous namespace, so all type information related to D should have
71  // internal linkage.
72  struct D { };
73
74  // E is also inside an anonymous namespace.
75  enum E { };
76
77};
78
79const D getD();
80
81const std::type_info &t2() {
82  (void)typeid(const D);
83  (void)typeid(D *);
84  (void)typeid(D (*)());
85  (void)typeid(void (*)(D));
86  // The exception specification is not part of the RTTI descriptor, so it should not have
87  // internal linkage.
88  (void)typeid(void (*)() throw (D));
89
90  (void)typeid(E);
91
92  // CHECK: _ZTIN12_GLOBAL__N_11DE to
93  return typeid(getD());
94}
95