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
16namespace Test1 {
17
18struct A {
19  A();
20  virtual void f();
21  virtual ~A() { }
22};
23
24A::A() { }
25
26void f(A* a) {
27  a->f();
28};
29
30// CHECK: define void @_ZN5Test11gEv
31// CHECK: call void @_ZN5Test11A1fEv
32void 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
47namespace Test2 {
48  struct A {
49    virtual void f();
50  };
51
52  const std::type_info &g() {
53    return typeid(A);
54  };
55
56  void A::f() { }
57}
58
59// Test that we don't assert on this test.
60namespace Test3 {
61
62struct A {
63  virtual void f();
64  virtual ~A() { }
65};
66
67struct B : A {
68  B();
69  virtual void f();
70};
71
72B::B() { }
73
74void g(A* a) {
75  a->f();
76};
77
78}
79
80// PR9114, test that we don't try to instantiate RefPtr<Node>.
81namespace Test4 {
82
83template <class T> struct RefPtr {
84  T* p;
85  ~RefPtr() {
86    p->deref();
87  }
88};
89
90struct A {
91  virtual ~A();
92};
93
94struct Node;
95
96struct B : A {
97  virtual void deref();
98  RefPtr<Node> m;
99};
100
101void 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
109namespace Test5 {
110
111struct A {
112  virtual void f() { }
113};
114
115struct B : A {
116  virtual ~B();
117};
118
119B::~B() { }
120
121}
122
123// Check that we don't assert on this test.
124namespace Test6 {
125
126struct A {
127  virtual ~A();
128  int a;
129};
130
131struct B {
132  virtual ~B();
133  int b;
134};
135
136struct C : A, B {
137  C();
138};
139
140struct D : C {
141  virtual void f();
142  D();
143};
144
145D::D() { }
146
147}
148
149namespace Test7 {
150
151struct c1 {};
152struct c10 : c1{
153  virtual void foo ();
154};
155struct c11 : c10, c1{
156  virtual void f6 ();
157};
158struct 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
165void check_c28 () {
166  c28 obj;
167  c11 *ptr = &obj;
168  ptr->f6 ();
169}
170
171}
172