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
10 // unit, but in order to devirtualize calls, we emit the v-table with
11 // available_externally linkage.
12 //
13 // There's no real reason to do this to the RTTI, though.
14 
15 // CHECK-TEST1: @_ZTVN5Test11AE = available_externally
16 // CHECK-TEST1: @_ZTIN5Test11AE = external constant i8*
17 namespace Test1 {
18 
19 struct A {
20   A();
21   virtual void f();
22   virtual ~A() { }
23 };
24 
25 A::A() { }
26 
27 void f(A* a) {
28   a->f();
29 };
30 
31 // CHECK: define void @_ZN5Test11gEv
32 // CHECK: call void @_ZN5Test11A1fEv
33 void 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
48 namespace 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 }
59 
60 // Test that we don't assert on this test.
61 namespace Test3 {
62 
63 struct A {
64   virtual void f();
65   virtual ~A() { }
66 };
67 
68 struct B : A {
69   B();
70   virtual void f();
71 };
72 
73 B::B() { }
74 
75 void g(A* a) {
76   a->f();
77 };
78 
79 }
80 
81 // PR9114, test that we don't try to instantiate RefPtr<Node>.
82 namespace Test4 {
83 
84 template <class T> struct RefPtr {
85   T* p;
86   ~RefPtr() {
87     p->deref();
88   }
89 };
90 
91 struct A {
92   virtual ~A();
93 };
94 
95 struct Node;
96 
97 struct B : A {
98   virtual void deref();
99   RefPtr<Node> m;
100 };
101 
102 void 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
110 namespace Test5 {
111 
112 struct A {
113   virtual void f() { }
114 };
115 
116 struct B : A {
117   virtual ~B();
118 };
119 
120 B::~B() { }
121 
122 }
123 
124 // Check that we don't assert on this test.
125 namespace Test6 {
126 
127 struct A {
128   virtual ~A();
129   int a;
130 };
131 
132 struct B {
133   virtual ~B();
134   int b;
135 };
136 
137 struct C : A, B {
138   C();
139 };
140 
141 struct D : C {
142   virtual void f();
143   D();
144 };
145 
146 D::D() { }
147 
148 }
149 
150 namespace Test7 {
151 
152 struct c1 {};
153 struct c10 : c1{
154   virtual void foo ();
155 };
156 struct c11 : c10, c1{
157   virtual void f6 ();
158 };
159 struct 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
166 void check_c28 () {
167   c28 obj;
168   c11 *ptr = &obj;
169   ptr->f6 ();
170 }
171 
172 }
173