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
9 namespace Test1 {
10 
11 struct A {
12   A();
13   virtual void f();
14   virtual ~A() { }
15 };
16 
17 A::A() { }
18 
19 void f(A* a) {
20   a->f();
21 };
22 
23 // CHECK-LABEL: define void @_ZN5Test11gEv
24 // CHECK: call void @_ZN5Test11A1fEv
25 void 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 = unnamed_addr constant
39 // CHECK-TEST2: @_ZTVN5Test21AE = unnamed_addr constant
40 namespace 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.
53 namespace Test3 {
54 
55 struct A {
56   virtual void f();
57   virtual ~A() { }
58 };
59 
60 struct B : A {
61   B();
62   virtual void f();
63 };
64 
65 B::B() { }
66 
67 void g(A* a) {
68   a->f();
69 };
70 
71 }
72 
73 // PR9114, test that we don't try to instantiate RefPtr<Node>.
74 namespace Test4 {
75 
76 template <class T> struct RefPtr {
77   T* p;
78   ~RefPtr() {
79     p->deref();
80   }
81 };
82 
83 struct A {
84   virtual ~A();
85 };
86 
87 struct Node;
88 
89 struct B : A {
90   virtual void deref();
91   RefPtr<Node> m;
92 };
93 
94 void 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
102 namespace Test5 {
103 
104 struct A {
105   virtual void f() { }
106 };
107 
108 struct B : A {
109   virtual ~B();
110 };
111 
112 B::~B() { }
113 
114 }
115 
116 // Check that we don't assert on this test.
117 namespace Test6 {
118 
119 struct A {
120   virtual ~A();
121   int a;
122 };
123 
124 struct B {
125   virtual ~B();
126   int b;
127 };
128 
129 struct C : A, B {
130   C();
131 };
132 
133 struct D : C {
134   virtual void f();
135   D();
136 };
137 
138 D::D() { }
139 
140 }
141 
142 namespace Test7 {
143 
144 struct c1 {};
145 struct c10 : c1{
146   virtual void foo ();
147 };
148 struct c11 : c10, c1{
149   virtual void f6 ();
150 };
151 struct c28 : virtual c11{
152   void f6 ();
153 };
154 }
155