blob: 693b36abe502c735f4ed80a5591eb1f0824567fd [file] [log] [blame]
Anders Carlsson6d7f8472011-01-30 20:45:54 +00001// 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
Anders Carlsson1faa89f2011-02-05 04:35:53 +00004// RUN: FileCheck --check-prefix=CHECK-TEST5 %s < %t
Anders Carlsson976d9112011-02-06 20:16:20 +00005// RUN: FileCheck --check-prefix=CHECK-TEST7 %s < %t
Anders Carlsson6d7f8472011-01-30 20:45:54 +00006
7#include <typeinfo>
8
John McCalld5617ee2013-01-25 22:31:03 +00009// Test1::A's key function (f) is not defined in this translation
10// unit, but in order to devirtualize calls, we emit the v-table with
Anders Carlsson6d7f8472011-01-30 20:45:54 +000011// available_externally linkage.
John McCalld5617ee2013-01-25 22:31:03 +000012//
13// There's no real reason to do this to the RTTI, though.
Anders Carlsson6d7f8472011-01-30 20:45:54 +000014
15// CHECK-TEST1: @_ZTVN5Test11AE = available_externally
John McCalld5617ee2013-01-25 22:31:03 +000016// CHECK-TEST1: @_ZTIN5Test11AE = external constant i8*
Anders Carlsson6d7f8472011-01-30 20:45:54 +000017namespace Test1 {
18
19struct A {
20 A();
21 virtual void f();
22 virtual ~A() { }
23};
24
25A::A() { }
26
27void f(A* a) {
28 a->f();
29};
30
31// CHECK: define void @_ZN5Test11gEv
32// CHECK: call void @_ZN5Test11A1fEv
33void g() {
34 A a;
35 f(&a);
36}
37
38}
39
40// Test2::A's key function (f) is defined in this translation unit, but when
41// we're doing codegen for the typeid(A) call, we don't know that yet.
42// This tests mainly that the typeinfo and typename constants have their linkage
43// updated correctly.
44
45// CHECK-TEST2: @_ZTSN5Test21AE = constant
46// CHECK-TEST2: @_ZTIN5Test21AE = unnamed_addr constant
47// CHECK-TEST2: @_ZTVN5Test21AE = unnamed_addr constant
48namespace Test2 {
49 struct A {
50 virtual void f();
51 };
52
53 const std::type_info &g() {
54 return typeid(A);
55 };
56
57 void A::f() { }
58}
Anders Carlsson1faa89f2011-02-05 04:35:53 +000059
60// Test that we don't assert on this test.
61namespace Test3 {
62
63struct A {
64 virtual void f();
65 virtual ~A() { }
66};
67
68struct B : A {
69 B();
70 virtual void f();
71};
72
73B::B() { }
74
75void g(A* a) {
76 a->f();
77};
78
79}
80
81// PR9114, test that we don't try to instantiate RefPtr<Node>.
82namespace Test4 {
83
84template <class T> struct RefPtr {
85 T* p;
86 ~RefPtr() {
87 p->deref();
88 }
89};
90
91struct A {
92 virtual ~A();
93};
94
95struct Node;
96
97struct B : A {
98 virtual void deref();
99 RefPtr<Node> m;
100};
101
102void f() {
103 RefPtr<B> b;
104}
105
106}
107
108// PR9130, test that we emit a definition of A::f.
109// CHECK-TEST5: define linkonce_odr void @_ZN5Test51A1fEv
110namespace Test5 {
111
112struct A {
113 virtual void f() { }
114};
115
116struct B : A {
117 virtual ~B();
118};
119
120B::~B() { }
121
122}
Anders Carlssonbbfd5ba2011-02-05 18:48:55 +0000123
124// Check that we don't assert on this test.
125namespace Test6 {
126
127struct A {
128 virtual ~A();
129 int a;
130};
131
132struct B {
133 virtual ~B();
134 int b;
135};
136
137struct C : A, B {
138 C();
139};
140
141struct D : C {
142 virtual void f();
143 D();
144};
145
146D::D() { }
147
148}
Anders Carlsson976d9112011-02-06 20:16:20 +0000149
150namespace Test7 {
151
152struct c1 {};
153struct c10 : c1{
154 virtual void foo ();
155};
156struct c11 : c10, c1{
157 virtual void f6 ();
158};
159struct c28 : virtual c11{
160 void f6 ();
161};
162
163// CHECK-TEST7: define void @_ZN5Test79check_c28Ev
164// CHECK-TEST7: call void @_ZN5Test73c282f6Ev
165// CHECK-TEST7: ret void
166void check_c28 () {
167 c28 obj;
168 c11 *ptr = &obj;
169 ptr->f6 ();
170}
171
172}