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