Clang Project

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