1 // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -std=c++98 -emit-llvm -o %t
2 // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -std=c++98 -O2 -disable-llvm-passes -emit-llvm -o %t.opt
3 // RUN: %clang_cc1 %s -I%S -triple=x86_64-apple-darwin10 -std=c++98 -O2 -disable-llvm-passes -emit-llvm -o %t.vtable -fforce-emit-vtables -fstrict-vtable-pointers -mconstructor-aliases
4 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-TEST1 %s < %t
5 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-TEST2 %s < %t
6 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-TEST5 %s < %t
7 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-TEST8 %s < %t.opt
8 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-TEST9 %s < %t.opt
9 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-TEST10 %s < %t.opt
10 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-TEST11 %s < %t.opt
11 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-TEST12 %s < %t.opt
12 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-TEST13 %s < %t.opt
13 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-TEST14 %s < %t.opt
14 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-TEST15 %s < %t.opt
15 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-TEST16 %s < %t.opt
16 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-TEST17 %s < %t.opt
17 // RUN: FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-FORCE-EMIT %s < %t.vtable
22 // CHECK-TEST1: @_ZTVN5Test11AE = external unnamed_addr constant
23 // CHECK-FORCE-EMIT-DAG: @_ZTVN5Test11AE = available_externally unnamed_addr constant
38 // CHECK-LABEL: define{{.*}} void @_ZN5Test11gEv
39 // CHECK: call void @_ZN5Test11A1fEv
47 // Test2::A's key function (f) is defined in this translation unit, but when
48 // we're doing codegen for the typeid(A) call, we don't know that yet.
49 // This tests mainly that the typeinfo and typename constants have their linkage
52 // CHECK-TEST2: @_ZTSN5Test21AE ={{.*}} constant
53 // CHECK-TEST2: @_ZTIN5Test21AE ={{.*}} constant
54 // CHECK-TEST2: @_ZTVN5Test21AE ={{.*}} unnamed_addr constant
60 const std::type_info
&g() {
67 // Test that we don't assert on this test.
88 // PR9114, test that we don't try to instantiate RefPtr<Node>.
91 template <class T
> struct RefPtr
{
105 virtual void deref();
115 // PR9130, test that we emit a definition of A::f.
116 // CHECK-TEST5-LABEL: define linkonce_odr void @_ZN5Test51A1fEv
131 // Check that we don't assert on this test.
163 struct c11
: c10
, c1
{
166 struct c28
: virtual c11
{
172 // CHECK-TEST8: @_ZTVN5Test81YE = available_externally unnamed_addr constant
173 // vtable for X is not generated because there are no stores here
182 void g(X
* p
) { p
->foo(); }
193 // All virtual functions are outline, so we can assume that it will
194 // be generated in translation unit where foo is defined.
195 // CHECK-TEST9-DAG: @_ZTVN5Test91AE = available_externally unnamed_addr constant
196 // CHECK-TEST9-DAG: @_ZTVN5Test91BE = available_externally unnamed_addr constant
218 // because A's key function is defined here, vtable is generated in this TU
219 // CHECK-TEST10-DAG: @_ZTVN6Test101AE ={{.*}} unnamed_addr constant
220 // CHECK-FORCE-EMIT-DAG: @_ZTVN6Test101AE ={{.*}} unnamed_addr constant
227 // Because key function is inline we will generate vtable as linkonce_odr.
228 // CHECK-TEST10-DAG: @_ZTVN6Test101DE = linkonce_odr unnamed_addr constant
229 // CHECK-FORCE-EMIT-DAG: @_ZTVN6Test101DE = linkonce_odr unnamed_addr constant
233 inline void D::bar() {}
235 // Because B has outline all virtual functions, we can refer to them.
236 // CHECK-TEST10-DAG: @_ZTVN6Test101BE = available_externally unnamed_addr constant
242 // C's key function (car) is outline, but C has inline virtual function so we
243 // can't guarantee that we will be able to refer to bar from name
244 // so (at the moment) we can't emit vtable available_externally.
245 // CHECK-TEST10-DAG: @_ZTVN6Test101CE = external unnamed_addr constant
246 // CHECK-FORCE-EMIT-DAG: @_ZTVN6Test101CE = available_externally unnamed_addr constant
248 void bar() {} // defined in body - not key function
249 virtual inline void gar(); // inline in body - not key function
253 // no key function, vtable will be generated everywhere it will be used
254 // CHECK-TEST10-DAG: @_ZTVN6Test101EE = linkonce_odr unnamed_addr constant
255 // CHECK-FORCE-EMIT-DAG: @_ZTVN6Test101EE = linkonce_odr unnamed_addr constant
281 // Can emit C's vtable available_externally.
282 // CHECK-TEST11: @_ZTVN6Test111CE = available_externally unnamed_addr constant
284 virtual D
& operator=(const D
&);
287 // Can emit D's vtable available_externally.
288 // CHECK-TEST11: @_ZTVN6Test111DE = available_externally unnamed_addr constant
309 // CHECK-TEST12: @_ZTVN6Test121AE = external unnamed_addr constant
310 // CHECK-FORCE-EMIT-DAG: @_ZTVN6Test121AE = available_externally unnamed_addr constant
315 // CHECK-TEST12: @_ZTVN6Test121BE = external unnamed_addr constant
316 // CHECK-FORCE-EMIT-DAG: @_ZTVN6Test121BE = available_externally unnamed_addr constant
331 // CHECK-TEST13-DAG: @_ZTVN6Test131AE = available_externally unnamed_addr constant
332 // CHECK-TEST13-DAG: @_ZTVN6Test131BE = external unnamed_addr constant
333 // CHECK-FORCE-EMIT-DAG: @_ZTVN6Test131AE = available_externally unnamed_addr constant
334 // CHECK-FORCE-EMIT-DAG: @_ZTVN6Test131BE = available_externally unnamed_addr constant
341 void operator delete(void *);
352 // CHECK-TEST14: @_ZTVN6Test141AE = available_externally unnamed_addr constant
355 void operator delete(void *);
366 // In this test D's vtable has two slots for function f(), but uses only one,
367 // so the second slot is set to null.
368 // CHECK-TEST15: @_ZTVN6Test151DE = available_externally unnamed_addr constant
369 struct A
{ virtual void f() {} };
370 struct B
: virtual A
{};
371 struct C
: virtual A
{};
384 // S has virtual method that is hidden, because of it we can't
385 // generate available_externally vtable for it.
386 // CHECK-TEST16-DAG: @_ZTVN6Test161SE = external unnamed_addr constant
387 // CHECK-TEST16-DAG: @_ZTVN6Test162S2E = available_externally
388 // CHECK-FORCE-EMIT-DAG: @_ZTVN6Test161SE = external unnamed_addr constant
389 // CHECK-FORCE-EMIT-DAG: @_ZTVN6Test162S2E = available_externally
392 __attribute__((visibility("hidden"))) virtual void doStuff();
396 virtual void doStuff();
397 __attribute__((visibility("hidden"))) void unused();
411 // This test checks if we emit vtables opportunistically.
412 // CHECK-TEST17-DAG: @_ZTVN6Test171AE = available_externally
413 // CHECK-TEST17-DAG: @_ZTVN6Test171BE = external
414 // CHECK-FORCE-EMIT-DAG: @_ZTVN6Test171AE = available_externally
415 // CHECK-FORCE-EMIT-DAG: @_ZTVN6Test171BE = available_externally
416 // CHECK-FORCE-EMIT-DAG: define linkonce_odr void @_ZN6Test171BD2Ev(
417 // CHECK-FORCE-EMIT-DAG: define linkonce_odr void @_ZN6Test171BD0Ev(
421 virtual void bar() {}
424 // We won't gonna use deleting destructor for this type, which will disallow
425 // emitting vtable as available_externally
433 a
.bar(); // this forces to emit definition of bar
437 B b
; // This only forces emitting of complete object destructor
440 } // namespace Test17
443 // Here vtable will be only emitted because it is referenced by assume-load
444 // after the Derived construction.
445 // CHECK-FORCE-EMIT-DAG: @_ZTVN6Test187DerivedE = linkonce_odr unnamed_addr constant {{.*}} @_ZTIN6Test187DerivedE, {{.*}} @_ZN6Test184Base3funEv, {{.*}} @_ZN6Test184BaseD2Ev, {{.*}} @_ZN6Test187DerivedD0Ev
446 // CHECK-FORCE-EMIT-DAG: define linkonce_odr void @_ZN6Test187DerivedD0Ev
447 // CHECK-FORCE-EMIT-DAG: define linkonce_odr void @_ZN6Test184BaseD2Ev
448 // CHECK-FORCE-EMIT-DAG: define linkonce_odr noundef i32 @_ZN6Test184Base3funEv
449 // CHECK-FORCE-EMIT-DAG: @_ZTIN6Test187DerivedE = linkonce_odr constant
452 virtual int fun() { return 42; }
456 struct Derived
: Base
{
461 Derived
*der
= new Derived();
466 namespace TestTemplates
{
468 // CHECK-FORCE-EMIT-DAG: @_ZTVN13TestTemplates8TemplateIiEE = linkonce_odr unnamed_addr constant {{.*}} @_ZTIN13TestTemplates8TemplateIiEE, {{.*}} @_ZN13TestTemplates8TemplateIiE3fooEi, {{.*}}@_ZN13TestTemplates8TemplateIiE22thisShouldBeEmittedTooEi, {{.*}}@_ZN13TestTemplates8TemplateIiED1Ev, {{.*}}@_ZN13TestTemplates8TemplateIiED0Ev
469 // CHECK-FORCE-EMIT-DAG: define linkonce_odr noundef i32 @_ZN13TestTemplates8TemplateIiE22thisShouldBeEmittedTooEi
474 virtual T
foo(T val
);
475 // CHECK-FORCE-EMIT-DAG: define linkonce_odr noundef i32 @_ZN13TestTemplates8TemplateIiE22thisShouldBeEmittedTooEi
476 virtual T
thisShouldBeEmittedToo(T val
) { return val
; }
484 virtual T
foo(T val
);
485 // CHECK-FORCE-EMIT-DAG: define linkonce_odr noundef i32 @_ZN13TestTemplates11NonTemplate22thisShouldBeEmittedTooEi
486 virtual T
thisShouldBeEmittedToo(T val
) { return val
; }
487 virtual ~NonTemplate();
490 // CHECK-FORCE-EMIT-DAG: @_ZTVN13TestTemplates16OuterNonTemplate27NestedTemplateInNonTemplateIiEE = linkonce_odr {{.*}} @_ZTIN13TestTemplates16OuterNonTemplate27NestedTemplateInNonTemplateIiEE, {{.*}} @_ZN13TestTemplates16OuterNonTemplate27NestedTemplateInNonTemplateIiE3fooEi, {{.*}} @_ZN13TestTemplates16OuterNonTemplate27NestedTemplateInNonTemplateIiE22thisShouldBeEmittedTooEi, {{.*}} @_ZN13TestTemplates16OuterNonTemplate27NestedTemplateInNonTemplateIiED1Ev, {{.*}} @_ZN13TestTemplates16OuterNonTemplate27NestedTemplateInNonTemplateIiED0Ev
492 struct OuterNonTemplate
{
494 struct NestedTemplateInNonTemplate
{
495 NestedTemplateInNonTemplate();
496 virtual T
foo(T val
);
497 // CHECK-FORCE-EMIT-DAG: define linkonce_odr noundef i32 @_ZN13TestTemplates16OuterNonTemplate27NestedTemplateInNonTemplateIiE22thisShouldBeEmittedTooEi
498 virtual T
thisShouldBeEmittedToo(T val
) { return val
; }
499 virtual ~NestedTemplateInNonTemplate();
502 struct NestedNonTemplateInNonTemplate
{
504 NestedNonTemplateInNonTemplate();
505 virtual T
foo(T val
);
506 // CHECK-FORCE-EMIT-DAG: define linkonce_odr noundef i32 @_ZN13TestTemplates16OuterNonTemplate30NestedNonTemplateInNonTemplate22thisShouldBeEmittedTooEi
507 virtual T
thisShouldBeEmittedToo(T val
) { return val
; }
508 virtual ~NestedNonTemplateInNonTemplate();
513 struct OuterTemplate
{
515 struct NestedTemplateInTemplate
{
516 NestedTemplateInTemplate();
517 virtual T
foo(T val
);
518 // CHECK-FORCE-EMIT-DAG: define linkonce_odr noundef i32 @_ZN13TestTemplates13OuterTemplateIlE24NestedTemplateInTemplateIiE22thisShouldBeEmittedTooEi
519 virtual T
thisShouldBeEmittedToo(T val
) { return val
; }
520 virtual ~NestedTemplateInTemplate();
523 struct NestedNonTemplateInTemplate
{
525 NestedNonTemplateInTemplate();
526 virtual T
foo(T val
);
527 // CHECK-FORCE-EMIT-DAG: define linkonce_odr noundef i32 @_ZN13TestTemplates13OuterTemplateIlE27NestedNonTemplateInTemplate22thisShouldBeEmittedTooEi
528 virtual T
thisShouldBeEmittedToo(T val
) { return val
; }
529 virtual ~NestedNonTemplateInTemplate();
540 use
<Template
<int> >();
541 use
<OuterTemplate
<long>::NestedTemplateInTemplate
<int> >();
542 use
<OuterNonTemplate::NestedTemplateInNonTemplate
<int> >();
545 use
<OuterTemplate
<long>::NestedNonTemplateInTemplate
>();
546 use
<OuterNonTemplate::NestedNonTemplateInNonTemplate
>();