-
Notifications
You must be signed in to change notification settings - Fork 13.4k
/
Copy pathcpp.test
530 lines (455 loc) · 11.7 KB
/
cpp.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: sed -e "s|DSTROOT|%/t|g" %t/inputs.json.in > %t/inputs.json
// Invoke C++ with no-rtti.
// RUN: clang-installapi -target arm64-apple-macos13.1 \
// RUN: -I%t/usr/include -I%t/usr/local/include -x c++ -dynamiclib \
// RUN: -install_name @rpath/lib/libcpp.dylib -fno-rtti \
// RUN: %t/inputs.json -o %t/no-rtti.tbd 2>&1 | FileCheck %s --allow-empty
// RUN: llvm-readtapi -compare %t/no-rtti.tbd \
// RUN: %t/expected-no-rtti.tbd 2>&1 | FileCheck %s --allow-empty
// Invoke C++ with rtti.
// RUN: clang-installapi -target arm64-apple-macos13.1 \
// RUN: -I%t/usr/include -I%t/usr/local/include -x c++ \
// RUN: -install_name @rpath/lib/libcpp.dylib -frtti -dynamiclib \
// RUN: %t/inputs.json -o %t/rtti.tbd 2>&1 | FileCheck %s --allow-empty
// RUN: llvm-readtapi -compare %t/rtti.tbd \
// RUN: %t/expected-rtti.tbd 2>&1 | FileCheck %s --allow-empty
// CHECK-NOT: error:
// CHECK-NOT: warning:
//--- usr/include/basic.h
#ifndef CPP_H
#define CPP_H
inline int foo(int x) { return x + 1; }
extern int bar(int x) { return x + 1; }
inline int baz(int x) {
static const int a[] = {1, 2, 3};
return a[x];
}
extern "C" {
int cFunc(const char*);
}
class Bar {
public:
static const int x = 0;
static int y;
inline int func1(int x) { return x + 2; }
inline int func2(int x);
int func3(int x);
};
class __attribute__((visibility("hidden"))) BarI {
static const int x = 0;
static int y;
inline int func1(int x) { return x + 2; }
inline int func2(int x);
int func3(int x);
};
int Bar::func2(int x) { return x + 3; }
inline int Bar::func3(int x) { return x + 4; }
int BarI::func2(int x) { return x + 3; }
inline int BarI::func3(int x) { return x + 4; }
#endif
//--- usr/local/include/vtable.h
// Simple test class with no virtual functions. There should be no vtable or
// RTTI.
namespace test1 {
class Simple {
public:
void run();
};
} // end namespace test1
// Simple test class with virtual function. There should be an external vtable
// and RTTI.
namespace test2 {
class Simple {
public:
virtual void run();
};
} // end namespace test2
// Abstract class with no sub classes. There should be no vtable or RTTI.
namespace test3 {
class Abstract {
public:
virtual ~Abstract() {}
virtual void run() = 0;
};
} // end namespace test3
// Abstract base class with a sub class. There should be weak-def RTTI for the
// abstract base class.
// The sub-class should have vtable and RTTI.
namespace test4 {
class Base {
public:
virtual ~Base() {}
virtual void run() = 0;
};
class Sub : public Base {
public:
void run() override;
};
} // end namespace test4
// Abstract base class with a sub class. Same as above, but with a user defined
// inlined destructor.
namespace test5 {
class Base {
public:
virtual ~Base() {}
virtual void run() = 0;
};
class Sub : public Base {
public:
virtual ~Sub() {}
void run() override;
};
} // end namespace test5
// Abstract base class with a sub class. Same as above, but with a different
// inlined key method.
namespace test6 {
class Base {
public:
virtual ~Base() {}
virtual void run() = 0;
};
class Sub : public Base {
public:
virtual void foo() {}
void run() override;
};
} // end namespace test6
// Abstract base class with a sub class. Overloaded method is implemented
// inline. No vtable or RTTI.
namespace test7 {
class Base {
public:
virtual ~Base() {}
virtual bool run() = 0;
};
class Sub : public Base {
public:
bool run() override { return true; }
};
} // end namespace test7
// Abstract base class with a sub class. Overloaded method has no inline
// attribute and is recognized as key method,
// but is later implemented inline. Weak-def RTTI only.
namespace test8 {
class Base {
public:
virtual ~Base() {}
virtual void run() = 0;
};
class Sub : public Base {
public:
void run() override;
};
inline void Sub::run() {}
} // end namespace test8
namespace test9 {
class Base {
public:
virtual ~Base() {}
virtual void run1() = 0;
virtual void run2() = 0;
};
class Sub : public Base {
public:
void run1() override {}
void run2() override;
};
inline void Sub::run2() {}
} // end namespace test9
namespace test10 {
class Base {
public:
virtual ~Base() {}
virtual void run1() = 0;
virtual void run2() = 0;
};
class Sub : public Base {
public:
void run1() override {}
inline void run2() override;
};
void Sub::run2() {}
} // end namespace test10
namespace test11 {
class Base {
public:
virtual ~Base() {}
virtual void run1() = 0;
virtual void run2() = 0;
virtual void run3() = 0;
};
class Sub : public Base {
public:
void run1() override {}
void run2() override;
void run3() override;
};
inline void Sub::run2() {}
} // end namespace test11
namespace test12 {
template <class T> class Simple {
public:
virtual void foo() {}
};
extern template class Simple<int>;
} // end namespace test12
namespace test13 {
class Base {
public:
virtual ~Base() {}
virtual void run1() = 0;
virtual void run2() {};
virtual void run3(); // key function.
};
class Sub : public Base {
public:
void run1() override {}
void run2() override {}
};
} // end namespace test13
namespace test14 {
class __attribute__((visibility("hidden"))) Base
{
public:
Base() {}
virtual ~Base(); // keyfunction.
virtual void run1() const = 0;
};
class Sub : public Base
{
public:
Sub();
virtual ~Sub();
virtual void run1() const;
void run2() const {}
};
} // end namespace test14
namespace test15 {
class Base {
public:
virtual ~Base() {}
virtual void run() {};
};
class Base1 {
public:
virtual ~Base1() {}
virtual void run1() {};
};
class Sub : public Base, public Base1 {
public:
Sub() {}
~Sub();
void run() override;
void run1() override;
};
class Sub1 : public Base, public Base1 {
public:
Sub1() {}
~Sub1() = default;
void run() override;
void run1() override;
};
} // end namespace test15
//--- usr/local/include/templates.h
#ifndef TEMPLATES_H
#define TEMPLATES_H
namespace templates {
// Full specialization.
template <class T> int foo1(T a) { return 1; }
template <> int foo1<int>(int a);
extern template int foo1<short>(short a);
template <class T> int foo2(T a);
// Partial specialization.
template <class A, class B> class Partial {
static int run(A a, B b) { return a + b; }
};
template <class A> class Partial<A, int> {
static int run(A a, int b) { return a - b; }
};
template <class T> class Foo {
public:
Foo();
~Foo();
};
template <class T> class Bar {
public:
Bar();
~Bar() {}
inline int bazinga() { return 7; }
};
extern template class Bar<int>;
class Bazz {
public:
Bazz() {}
template <class T> int buzz(T a);
float implicit() const { return foo1(0.0f); }
};
template <class T> int Bazz::buzz(T a) { return sizeof(T); }
template <class T> struct S { static int x; };
template <class T> int S<T>::x = 0;
} // end namespace templates.
#endif
//--- inputs.json.in
{
"headers": [ {
"path" : "DSTROOT/usr/include/basic.h",
"type" : "public"
},
{
"path" : "DSTROOT/usr/local/include/vtable.h",
"type" : "private"
},
{
"path" : "DSTROOT/usr/local/include/templates.h",
"type" : "private"
}
],
"version": "3"
}
//--- expected-no-rtti.tbd
{
"main_library": {
"compatibility_versions": [
{
"version": "0"
}
],
"current_versions": [
{
"version": "0"
}
],
"exported_symbols": [
{
"data": {
"global": [
"__ZTVN6test143SubE", "__ZTVN6test113SubE", "__ZTVN5test26SimpleE",
"__ZTVN5test53SubE", "__ZTVN6test154Sub1E", "__ZTVN6test153SubE",
"__ZN3Bar1yE", "__ZTVN5test43SubE", "__ZTVN5test63SubE",
"__ZTVN6test134BaseE"
],
"weak": [
"__ZTVN6test126SimpleIiEE"
]
},
"text": {
"global": [
"__ZN6test153Sub3runEv", "__ZN6test154Sub13runEv",
"__Z3bari", "__ZThn8_N6test153SubD1Ev",
"__ZNK6test143Sub4run1Ev", "__ZN6test154Sub14run1Ev",
"__ZThn8_N6test153Sub4run1Ev", "__ZN6test143SubD1Ev",
"__ZN6test134Base4run3Ev", "__ZN5test16Simple3runEv",
"__ZN5test43Sub3runEv", "__ZN6test113Sub4run3Ev", "__ZN6test153SubD2Ev",
"__ZN5test53Sub3runEv", "__ZN6test153SubD1Ev", "__ZN6test143SubC1Ev",
"__ZN9templates4foo1IiEEiT_", "__ZN6test143SubC2Ev", "__ZN5test63Sub3runEv",
"__ZN5test26Simple3runEv", "__ZN6test153SubD0Ev",
"__ZN6test143SubD2Ev", "__ZN6test153Sub4run1Ev", "__ZN6test143SubD0Ev",
"__ZThn8_N6test153SubD0Ev", "__ZThn8_N6test154Sub14run1Ev", "_cFunc"
],
"weak": [
"__ZN9templates3BarIiED2Ev", "__ZN9templates3BarIiEC2Ev",
"__ZN9templates3BarIiEC1Ev", "__ZN9templates3BarIiED1Ev",
"__ZN6test126SimpleIiE3fooEv", "__ZN9templates3BarIiE7bazingaEv",
"__ZN9templates4foo1IsEEiT_"
]
}
}
],
"flags": [
{
"attributes": [
"not_app_extension_safe"
]
}
],
"install_names": [
{
"name": "@rpath/lib/libcpp.dylib"
}
],
"target_info": [
{
"min_deployment": "13.1",
"target": "arm64-macos"
}
]
},
"tapi_tbd_version": 5
}
//--- expected-rtti.tbd
{
"main_library": {
"compatibility_versions": [
{
"version": "0"
}
],
"current_versions": [
{
"version": "0"
}
],
"exported_symbols": [
{
"data": {
"global": [
"__ZTVN6test143SubE", "__ZTIN5test63SubE", "__ZTSN5test26SimpleE",
"__ZTIN6test153SubE", "__ZTVN6test113SubE", "__ZTIN5test43SubE",
"__ZTIN6test134BaseE", "__ZTVN5test26SimpleE", "__ZTIN5test26SimpleE",
"__ZTSN6test134BaseE", "__ZTVN6test154Sub1E", "__ZTVN5test43SubE",
"__ZTVN5test63SubE", "__ZTSN5test43SubE", "__ZTSN6test113SubE",
"__ZTIN6test154Sub1E", "__ZTSN6test153SubE", "__ZTSN5test63SubE",
"__ZTSN6test154Sub1E", "__ZTIN6test113SubE", "__ZTSN6test143SubE",
"__ZTVN5test53SubE", "__ZTIN6test143SubE", "__ZTVN6test153SubE",
"__ZTIN5test53SubE", "__ZN3Bar1yE", "__ZTVN6test134BaseE",
"__ZTSN5test53SubE"
],
"weak": [
"__ZTVN6test126SimpleIiEE"
]
},
"text": {
"global": [
"__ZN6test154Sub13runEv", "__ZN6test153Sub3runEv", "__ZNK6test143Sub4run1Ev",
"__ZN6test134Base4run3Ev", "__ZN5test16Simple3runEv", "__ZN6test153SubD2Ev",
"__ZN6test143SubC2Ev", "__ZN5test63Sub3runEv", "__ZN6test153SubD0Ev",
"__ZN6test143SubD2Ev", "__ZThn8_N6test154Sub14run1Ev",
"__ZThn8_N6test153SubD0Ev", "__Z3bari", "__ZThn8_N6test153SubD1Ev",
"__ZN6test154Sub14run1Ev", "__ZThn8_N6test153Sub4run1Ev",
"__ZN6test143SubD1Ev", "__ZN5test43Sub3runEv",
"__ZN6test113Sub4run3Ev", "__ZN5test53Sub3runEv", "__ZN6test143SubC1Ev",
"__ZN6test153SubD1Ev", "__ZN9templates4foo1IiEEiT_", "__ZN5test26Simple3runEv",
"__ZN6test153Sub4run1Ev", "__ZN6test143SubD0Ev", "_cFunc"
],
"weak": [
"__ZN9templates3BarIiEC2Ev", "__ZN9templates3BarIiEC1Ev",
"__ZN9templates3BarIiED1Ev", "__ZN6test126SimpleIiE3fooEv",
"__ZN9templates4foo1IsEEiT_", "__ZN9templates3BarIiED2Ev",
"__ZN9templates3BarIiE7bazingaEv"
]
}
}
],
"flags": [
{
"attributes": [
"not_app_extension_safe"
]
}
],
"install_names": [
{
"name": "@rpath/lib/libcpp.dylib"
}
],
"target_info": [
{
"min_deployment": "13.1",
"target": "arm64-macos"
}
]
},
"tapi_tbd_version": 5
}