xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/vtable-key-function-ios.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -triple=armv7-apple-darwin -emit-llvm -o - | FileCheck %s
2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -triple=armv7-apple-darwin -emit-llvm -o - | FileCheck -check-prefix=CHECK-LATE %s
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc // The 'a' variants ask for the v-table first.
5*f4a2713aSLionel Sambuc // The 'b' variants ask for the v-table second.
6*f4a2713aSLionel Sambuc // The 'c' variants ask for the v-table third.
7*f4a2713aSLionel Sambuc // We do a separate CHECK-LATE pass because the RTTI defintion gets
8*f4a2713aSLionel Sambuc // changed after the fact, which causes reordering of the globals.
9*f4a2713aSLionel Sambuc 
10*f4a2713aSLionel Sambuc // These are not separated into namespaces because the way that Sema
11*f4a2713aSLionel Sambuc // currently reports namespaces to IR-generation (i.e., en masse for
12*f4a2713aSLionel Sambuc // the entire namespace at once) subverts the ordering that we're
13*f4a2713aSLionel Sambuc // trying to test.
14*f4a2713aSLionel Sambuc 
15*f4a2713aSLionel Sambuc namespace std { class type_info; }
16*f4a2713aSLionel Sambuc extern void use(const std::type_info &rtti);
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc /*** Test0a ******************************************************************/
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc struct Test0a {
21*f4a2713aSLionel Sambuc   Test0a();
22*f4a2713aSLionel Sambuc   virtual inline void foo();
23*f4a2713aSLionel Sambuc   virtual void bar();
24*f4a2713aSLionel Sambuc };
25*f4a2713aSLionel Sambuc 
26*f4a2713aSLionel Sambuc // V-table should be defined externally.
27*f4a2713aSLionel Sambuc Test0a::Test0a() { use(typeid(Test0a)); }
28*f4a2713aSLionel Sambuc // CHECK: @_ZTV6Test0a = external unnamed_addr constant
29*f4a2713aSLionel Sambuc // CHECK: @_ZTI6Test0a = external constant
30*f4a2713aSLionel Sambuc 
31*f4a2713aSLionel Sambuc // This is not a key function.
32*f4a2713aSLionel Sambuc void Test0a::foo() {}
33*f4a2713aSLionel Sambuc 
34*f4a2713aSLionel Sambuc /*** Test0b ******************************************************************/
35*f4a2713aSLionel Sambuc 
36*f4a2713aSLionel Sambuc struct Test0b {
37*f4a2713aSLionel Sambuc   Test0b();
38*f4a2713aSLionel Sambuc   virtual inline void foo();
39*f4a2713aSLionel Sambuc   virtual void bar();
40*f4a2713aSLionel Sambuc };
41*f4a2713aSLionel Sambuc 
42*f4a2713aSLionel Sambuc // This is not a key function.
43*f4a2713aSLionel Sambuc void Test0b::foo() {}
44*f4a2713aSLionel Sambuc 
45*f4a2713aSLionel Sambuc // V-table should be defined externally.
46*f4a2713aSLionel Sambuc Test0b::Test0b() { use(typeid(Test0b)); }
47*f4a2713aSLionel Sambuc // CHECK: @_ZTV6Test0b = external unnamed_addr constant
48*f4a2713aSLionel Sambuc // CHECK: @_ZTI6Test0b = external constant
49*f4a2713aSLionel Sambuc 
50*f4a2713aSLionel Sambuc /*** Test1a ******************************************************************/
51*f4a2713aSLionel Sambuc 
52*f4a2713aSLionel Sambuc struct Test1a {
53*f4a2713aSLionel Sambuc   Test1a();
54*f4a2713aSLionel Sambuc   virtual void foo();
55*f4a2713aSLionel Sambuc   virtual void bar();
56*f4a2713aSLionel Sambuc };
57*f4a2713aSLionel Sambuc 
58*f4a2713aSLionel Sambuc // V-table needs to be defined weakly.
59*f4a2713aSLionel Sambuc Test1a::Test1a() { use(typeid(Test1a)); }
60*f4a2713aSLionel Sambuc // CHECK:      @_ZTV6Test1a = linkonce_odr unnamed_addr constant
61*f4a2713aSLionel Sambuc // CHECK-LATE: @_ZTS6Test1a = linkonce_odr constant
62*f4a2713aSLionel Sambuc // CHECK-LATE: @_ZTI6Test1a = linkonce_odr unnamed_addr constant
63*f4a2713aSLionel Sambuc 
64*f4a2713aSLionel Sambuc // This defines the key function.
65*f4a2713aSLionel Sambuc inline void Test1a::foo() {}
66*f4a2713aSLionel Sambuc 
67*f4a2713aSLionel Sambuc /*** Test1b ******************************************************************/
68*f4a2713aSLionel Sambuc 
69*f4a2713aSLionel Sambuc struct Test1b {
70*f4a2713aSLionel Sambuc   Test1b();
71*f4a2713aSLionel Sambuc   virtual void foo();
72*f4a2713aSLionel Sambuc   virtual void bar();
73*f4a2713aSLionel Sambuc };
74*f4a2713aSLionel Sambuc 
75*f4a2713aSLionel Sambuc // This defines the key function.
76*f4a2713aSLionel Sambuc inline void Test1b::foo() {}
77*f4a2713aSLionel Sambuc 
78*f4a2713aSLionel Sambuc // V-table should be defined weakly..
79*f4a2713aSLionel Sambuc Test1b::Test1b() { use(typeid(Test1b)); }
80*f4a2713aSLionel Sambuc // CHECK: @_ZTV6Test1b = linkonce_odr unnamed_addr constant
81*f4a2713aSLionel Sambuc // CHECK: @_ZTS6Test1b = linkonce_odr constant
82*f4a2713aSLionel Sambuc // CHECK: @_ZTI6Test1b = linkonce_odr unnamed_addr constant
83*f4a2713aSLionel Sambuc 
84*f4a2713aSLionel Sambuc /*** Test2a ******************************************************************/
85*f4a2713aSLionel Sambuc 
86*f4a2713aSLionel Sambuc struct Test2a {
87*f4a2713aSLionel Sambuc   Test2a();
88*f4a2713aSLionel Sambuc   virtual void foo();
89*f4a2713aSLionel Sambuc   virtual void bar();
90*f4a2713aSLionel Sambuc };
91*f4a2713aSLionel Sambuc 
92*f4a2713aSLionel Sambuc // V-table should be defined with weak linkage.
93*f4a2713aSLionel Sambuc Test2a::Test2a() { use(typeid(Test2a)); }
94*f4a2713aSLionel Sambuc // CHECK:      @_ZTV6Test2a = linkonce_odr unnamed_addr constant
95*f4a2713aSLionel Sambuc // CHECK-LATE: @_ZTS6Test2a = linkonce_odr constant
96*f4a2713aSLionel Sambuc // CHECK-LATE: @_ZTI6Test2a = linkonce_odr unnamed_addr constant
97*f4a2713aSLionel Sambuc 
98*f4a2713aSLionel Sambuc void Test2a::bar() {}
99*f4a2713aSLionel Sambuc inline void Test2a::foo() {}
100*f4a2713aSLionel Sambuc 
101*f4a2713aSLionel Sambuc /*** Test2b ******************************************************************/
102*f4a2713aSLionel Sambuc 
103*f4a2713aSLionel Sambuc struct Test2b {
104*f4a2713aSLionel Sambuc   Test2b();
105*f4a2713aSLionel Sambuc   virtual void foo();
106*f4a2713aSLionel Sambuc   virtual void bar();
107*f4a2713aSLionel Sambuc };
108*f4a2713aSLionel Sambuc 
109*f4a2713aSLionel Sambuc void Test2b::bar() {}
110*f4a2713aSLionel Sambuc 
111*f4a2713aSLionel Sambuc // V-table should be defined with weak linkage.
112*f4a2713aSLionel Sambuc Test2b::Test2b() { use(typeid(Test2b)); }
113*f4a2713aSLionel Sambuc // CHECK:      @_ZTV6Test2b = linkonce_odr unnamed_addr constant
114*f4a2713aSLionel Sambuc // CHECK-LATE: @_ZTS6Test2b = linkonce_odr constant
115*f4a2713aSLionel Sambuc // CHECK-LATE: @_ZTI6Test2b = linkonce_odr unnamed_addr constant
116*f4a2713aSLionel Sambuc 
117*f4a2713aSLionel Sambuc inline void Test2b::foo() {}
118*f4a2713aSLionel Sambuc 
119*f4a2713aSLionel Sambuc /*** Test2c ******************************************************************/
120*f4a2713aSLionel Sambuc 
121*f4a2713aSLionel Sambuc struct Test2c {
122*f4a2713aSLionel Sambuc   Test2c();
123*f4a2713aSLionel Sambuc   virtual void foo();
124*f4a2713aSLionel Sambuc   virtual void bar();
125*f4a2713aSLionel Sambuc };
126*f4a2713aSLionel Sambuc 
127*f4a2713aSLionel Sambuc void Test2c::bar() {}
128*f4a2713aSLionel Sambuc inline void Test2c::foo() {}
129*f4a2713aSLionel Sambuc 
130*f4a2713aSLionel Sambuc // V-table should be defined with weak linkage.
131*f4a2713aSLionel Sambuc Test2c::Test2c() { use(typeid(Test2c)); }
132*f4a2713aSLionel Sambuc // CHECK: @_ZTV6Test2c = linkonce_odr unnamed_addr constant
133*f4a2713aSLionel Sambuc // CHECK: @_ZTS6Test2c = linkonce_odr constant
134*f4a2713aSLionel Sambuc // CHECK: @_ZTI6Test2c = linkonce_odr unnamed_addr constant
135*f4a2713aSLionel Sambuc 
136*f4a2713aSLionel Sambuc /*** Test3a ******************************************************************/
137*f4a2713aSLionel Sambuc 
138*f4a2713aSLionel Sambuc struct Test3a {
139*f4a2713aSLionel Sambuc   Test3a();
140*f4a2713aSLionel Sambuc   virtual void foo();
141*f4a2713aSLionel Sambuc   virtual void bar();
142*f4a2713aSLionel Sambuc };
143*f4a2713aSLionel Sambuc 
144*f4a2713aSLionel Sambuc // V-table should be defined with weak linkage.
145*f4a2713aSLionel Sambuc Test3a::Test3a() { use(typeid(Test3a)); }
146*f4a2713aSLionel Sambuc // CHECK:      @_ZTV6Test3a = linkonce_odr unnamed_addr constant
147*f4a2713aSLionel Sambuc // CHECK-LATE: @_ZTS6Test3a = linkonce_odr constant
148*f4a2713aSLionel Sambuc // CHECK-LATE: @_ZTI6Test3a = linkonce_odr unnamed_addr constant
149*f4a2713aSLionel Sambuc 
150*f4a2713aSLionel Sambuc // This defines the key function.
151*f4a2713aSLionel Sambuc inline void Test3a::bar() {}
152*f4a2713aSLionel Sambuc inline void Test3a::foo() {}
153*f4a2713aSLionel Sambuc 
154*f4a2713aSLionel Sambuc /*** Test3b ******************************************************************/
155*f4a2713aSLionel Sambuc 
156*f4a2713aSLionel Sambuc struct Test3b {
157*f4a2713aSLionel Sambuc   Test3b();
158*f4a2713aSLionel Sambuc   virtual void foo();
159*f4a2713aSLionel Sambuc   virtual void bar();
160*f4a2713aSLionel Sambuc };
161*f4a2713aSLionel Sambuc 
162*f4a2713aSLionel Sambuc inline void Test3b::bar() {}
163*f4a2713aSLionel Sambuc 
164*f4a2713aSLionel Sambuc // V-table should be defined with weak linkage.
165*f4a2713aSLionel Sambuc Test3b::Test3b() { use(typeid(Test3b)); }
166*f4a2713aSLionel Sambuc // CHECK:      @_ZTV6Test3b = linkonce_odr unnamed_addr constant
167*f4a2713aSLionel Sambuc // CHECK-LATE: @_ZTS6Test3b = linkonce_odr constant
168*f4a2713aSLionel Sambuc // CHECK-LATE: @_ZTI6Test3b = linkonce_odr unnamed_addr constant
169*f4a2713aSLionel Sambuc 
170*f4a2713aSLionel Sambuc // This defines the key function.
171*f4a2713aSLionel Sambuc inline void Test3b::foo() {}
172*f4a2713aSLionel Sambuc 
173*f4a2713aSLionel Sambuc /*** Test3c ******************************************************************/
174*f4a2713aSLionel Sambuc 
175*f4a2713aSLionel Sambuc struct Test3c {
176*f4a2713aSLionel Sambuc   Test3c();
177*f4a2713aSLionel Sambuc   virtual void foo();
178*f4a2713aSLionel Sambuc   virtual void bar();
179*f4a2713aSLionel Sambuc };
180*f4a2713aSLionel Sambuc 
181*f4a2713aSLionel Sambuc // This defines the key function.
182*f4a2713aSLionel Sambuc inline void Test3c::bar() {}
183*f4a2713aSLionel Sambuc inline void Test3c::foo() {}
184*f4a2713aSLionel Sambuc 
185*f4a2713aSLionel Sambuc // V-table should be defined with weak linkage.
186*f4a2713aSLionel Sambuc Test3c::Test3c() { use(typeid(Test3c)); }
187*f4a2713aSLionel Sambuc // CHECK: @_ZTV6Test3c = linkonce_odr unnamed_addr constant
188*f4a2713aSLionel Sambuc // CHECK: @_ZTS6Test3c = linkonce_odr constant
189*f4a2713aSLionel Sambuc // CHECK: @_ZTI6Test3c = linkonce_odr unnamed_addr constant
190