blob: 02b1d5c748346a56ea320a652583a6f6c401850d [file] [log] [blame]
Douglas Gregor6fb745b2010-05-13 16:44:06 +00001// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o %t
2// RUN: FileCheck --check-prefix=CHECK-1 %s < %t
3// RUN: FileCheck --check-prefix=CHECK-2 %s < %t
4// RUN: FileCheck --check-prefix=CHECK-3 %s < %t
5// RUN: FileCheck --check-prefix=CHECK-4 %s < %t
6// RUN: FileCheck --check-prefix=CHECK-5 %s < %t
7// RUN: FileCheck --check-prefix=CHECK-6 %s < %t
8// RUN: FileCheck --check-prefix=CHECK-7 %s < %t
9// RUN: FileCheck --check-prefix=CHECK-8 %s < %t
10// RUN: FileCheck --check-prefix=CHECK-9 %s < %t
11// RUN: FileCheck --check-prefix=CHECK-10 %s < %t
12// RUN: FileCheck --check-prefix=CHECK-11 %s < %t
13// RUN: FileCheck --check-prefix=CHECK-12 %s < %t
Anders Carlsson7ca46432009-12-05 17:04:47 +000014
15namespace {
Anders Carlsson7ca46432009-12-05 17:04:47 +000016 struct A {
17 virtual void f() { }
18 };
Anders Carlsson7ca46432009-12-05 17:04:47 +000019}
20
Anders Carlsson152d4dc2009-12-05 22:19:10 +000021void f() { A b; }
22
23struct B {
24 B();
25 virtual void f();
26};
27
28B::B() { }
29
Anders Carlsson891c8b72009-12-05 22:24:38 +000030struct C {
31 C();
32 virtual void f() { }
33};
34
35C::C() { }
36
Anders Carlsson5794c972009-12-06 00:53:22 +000037struct D {
38 virtual void f();
39};
40
41void D::f() { }
42
Eli Friedman470fb732009-12-11 20:48:18 +000043static struct : D { } e;
44
Douglas Gregor074a2cf2010-01-05 21:40:05 +000045// The destructor is the key function.
Douglas Gregorbd6d6192010-01-05 19:06:31 +000046template<typename T>
47struct E {
48 virtual ~E();
49};
50
51template<typename T> E<T>::~E() { }
52
Douglas Gregor074a2cf2010-01-05 21:40:05 +000053// Anchor is the key function
Douglas Gregorbd6d6192010-01-05 19:06:31 +000054template<>
55struct E<char> {
56 virtual void anchor();
57};
58
59void E<char>::anchor() { }
60
61template struct E<short>;
62extern template struct E<int>;
63
64void use_E() {
65 E<int> ei;
66 (void)ei;
67 E<long> el;
68 (void)el;
69}
70
Douglas Gregor074a2cf2010-01-05 21:40:05 +000071// No key function
72template<typename T>
73struct F {
74 virtual void foo() { }
75};
76
77// No key function
78template<>
79struct F<char> {
80 virtual void foo() { }
81};
82
83template struct F<short>;
84extern template struct F<int>;
85
86void use_F(F<char> &fc) {
87 F<int> fi;
Douglas Gregor6fb745b2010-05-13 16:44:06 +000088 fi.foo();
Douglas Gregor074a2cf2010-01-05 21:40:05 +000089 F<long> fl;
90 (void)fl;
91 fc.foo();
92}
93
Anders Carlsson152d4dc2009-12-05 22:19:10 +000094// B has a key function that is not defined in this translation unit so its vtable
95// has external linkage.
Douglas Gregor6fb745b2010-05-13 16:44:06 +000096// CHECK-1: @_ZTV1B = external constant
Anders Carlsson152d4dc2009-12-05 22:19:10 +000097
Anders Carlsson891c8b72009-12-05 22:24:38 +000098// C has no key function, so its vtable should have weak_odr linkage.
Douglas Gregor6fb745b2010-05-13 16:44:06 +000099// CHECK-2: @_ZTV1C = weak_odr constant
100// CHECK-2: @_ZTS1C = weak_odr constant
101// CHECK-2: @_ZTI1C = weak_odr constant
Anders Carlsson891c8b72009-12-05 22:24:38 +0000102
Anders Carlsson5794c972009-12-06 00:53:22 +0000103// D has a key function that is defined in this translation unit so its vtable is
104// defined in the translation unit.
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000105// CHECK-3: @_ZTV1D = constant
106// CHECK-3: @_ZTS1D = constant
107// CHECK-3: @_ZTI1D = constant
Anders Carlsson5794c972009-12-06 00:53:22 +0000108
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000109// E<char> is an explicit specialization with a key function defined
110// in this translation unit, so its vtable should have external
111// linkage.
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000112// CHECK-4: @_ZTV1EIcE = constant
113// CHECK-4: @_ZTS1EIcE = constant
114// CHECK-4: @_ZTI1EIcE = constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000115
116// E<short> is an explicit template instantiation with a key function
117// defined in this translation unit, so its vtable should have
118// weak_odr linkage.
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000119// CHECK-5: @_ZTV1EIsE = weak_odr constant
120// CHECK-5: @_ZTS1EIsE = weak_odr constant
121// CHECK-5: @_ZTI1EIsE = weak_odr constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000122
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000123// F<short> is an explicit template instantiation without a key
124// function, so its vtable should have weak_odr linkage
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000125// CHECK-6: @_ZTV1FIsE = weak_odr constant
126// CHECK-6: @_ZTS1FIsE = weak_odr constant
127// CHECK-6: @_ZTI1FIsE = weak_odr constant
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000128
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000129// E<long> is an implicit template instantiation with a key function
130// defined in this translation unit, so its vtable should have
131// weak_odr linkage.
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000132// CHECK-7: @_ZTV1EIlE = weak_odr constant
133// CHECK-7: @_ZTS1EIlE = weak_odr constant
134// CHECK-7: @_ZTI1EIlE = weak_odr constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000135
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000136// F<long> is an implicit template instantiation with no key function,
137// so its vtable should have weak_odr linkage.
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000138// CHECK-8: @_ZTV1FIlE = weak_odr constant
139// CHECK-8: @_ZTS1FIlE = weak_odr constant
140// CHECK-8: @_ZTI1FIlE = weak_odr constant
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000141
142// F<int> is an explicit template instantiation declaration without a
Rafael Espindola35d64612010-04-03 04:26:42 +0000143// key function, so its vtable should have external linkage.
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000144// CHECK-9: @_ZTV1FIiE = external constant
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000145
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000146// E<int> is an explicit template instantiation declaration. It has a
Douglas Gregorc84622a2010-01-07 04:09:30 +0000147// key function that is not instantiated, so we should only reference
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000148// its vtable, not define it.
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000149// CHECK-10: @_ZTV1EIiE = external constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000150
Eli Friedman6c6bda32010-01-08 00:50:11 +0000151// The anonymous struct for e has no linkage, so the vtable should have
152// internal linkage.
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000153// CHECK-11: @"_ZTV3$_0" = internal constant
154// CHECK-11: @"_ZTS3$_0" = internal constant
155// CHECK-11: @"_ZTI3$_0" = internal constant
Eli Friedman6c6bda32010-01-08 00:50:11 +0000156
Anders Carlsson152d4dc2009-12-05 22:19:10 +0000157// The A vtable should have internal linkage since it is inside an anonymous
158// namespace.
Douglas Gregor6fb745b2010-05-13 16:44:06 +0000159// CHECK-12: @_ZTVN12_GLOBAL__N_11AE = internal constant
160// CHECK-12: @_ZTSN12_GLOBAL__N_11AE = internal constant
161// CHECK-12: @_ZTIN12_GLOBAL__N_11AE = internal constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000162
163