1 // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -emit-llvm -O3 -o %t
2 // RUN: FileCheck --check-prefix=CHECK-TEST1 %s < %t
3 // RUN: FileCheck --check-prefix=CHECK-TEST2 %s < %t
4 // RUN: FileCheck --check-prefix=CHECK-TEST5 %s < %t
5 // RUN: FileCheck --check-prefix=CHECK-TEST7 %s < %t
6
7 #include <typeinfo>
8
9 // Test1::A's key function (f) is not defined in this translation unit, but in
10 // order to devirtualize calls, we emit the class related data with
11 // available_externally linkage.
12
13 // CHECK-TEST1: @_ZTVN5Test11AE = available_externally
14 // CHECK-TEST1: @_ZTSN5Test11AE = available_externally
15 // CHECK-TEST1: @_ZTIN5Test11AE = available_externally
16 namespace Test1 {
17
18 struct A {
19 A();
20 virtual void f();
~ATest1::A21 virtual ~A() { }
22 };
23
A()24 A::A() { }
25
f(A * a)26 void f(A* a) {
27 a->f();
28 };
29
30 // CHECK: define void @_ZN5Test11gEv
31 // CHECK: call void @_ZN5Test11A1fEv
g()32 void g() {
33 A a;
34 f(&a);
35 }
36
37 }
38
39 // Test2::A's key function (f) is defined in this translation unit, but when
40 // we're doing codegen for the typeid(A) call, we don't know that yet.
41 // This tests mainly that the typeinfo and typename constants have their linkage
42 // updated correctly.
43
44 // CHECK-TEST2: @_ZTSN5Test21AE = constant
45 // CHECK-TEST2: @_ZTIN5Test21AE = unnamed_addr constant
46 // CHECK-TEST2: @_ZTVN5Test21AE = unnamed_addr constant
47 namespace Test2 {
48 struct A {
49 virtual void f();
50 };
51
g()52 const std::type_info &g() {
53 return typeid(A);
54 };
55
f()56 void A::f() { }
57 }
58
59 // Test that we don't assert on this test.
60 namespace Test3 {
61
62 struct A {
63 virtual void f();
~ATest3::A64 virtual ~A() { }
65 };
66
67 struct B : A {
68 B();
69 virtual void f();
70 };
71
B()72 B::B() { }
73
g(A * a)74 void g(A* a) {
75 a->f();
76 };
77
78 }
79
80 // PR9114, test that we don't try to instantiate RefPtr<Node>.
81 namespace Test4 {
82
83 template <class T> struct RefPtr {
84 T* p;
~RefPtrTest4::RefPtr85 ~RefPtr() {
86 p->deref();
87 }
88 };
89
90 struct A {
91 virtual ~A();
92 };
93
94 struct Node;
95
96 struct B : A {
97 virtual void deref();
98 RefPtr<Node> m;
99 };
100
f()101 void f() {
102 RefPtr<B> b;
103 }
104
105 }
106
107 // PR9130, test that we emit a definition of A::f.
108 // CHECK-TEST5: define linkonce_odr void @_ZN5Test51A1fEv
109 namespace Test5 {
110
111 struct A {
fTest5::A112 virtual void f() { }
113 };
114
115 struct B : A {
116 virtual ~B();
117 };
118
~B()119 B::~B() { }
120
121 }
122
123 // Check that we don't assert on this test.
124 namespace Test6 {
125
126 struct A {
127 virtual ~A();
128 int a;
129 };
130
131 struct B {
132 virtual ~B();
133 int b;
134 };
135
136 struct C : A, B {
137 C();
138 };
139
140 struct D : C {
141 virtual void f();
142 D();
143 };
144
D()145 D::D() { }
146
147 }
148
149 namespace Test7 {
150
151 struct c1 {};
152 struct c10 : c1{
153 virtual void foo ();
154 };
155 struct c11 : c10, c1{
156 virtual void f6 ();
157 };
158 struct c28 : virtual c11{
159 void f6 ();
160 };
161
162 // CHECK-TEST7: define void @_ZN5Test79check_c28Ev
163 // CHECK-TEST7: call void @_ZN5Test73c282f6Ev
164 // CHECK-TEST7: ret void
check_c28()165 void check_c28 () {
166 c28 obj;
167 c11 *ptr = &obj;
168 ptr->f6 ();
169 }
170
171 }
172