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