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