blob: 733a9f0be538504a4cafd8a4d5d631ae7206c2b7 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s
Anders Carlsson7ca46432009-12-05 17:04:47 +00002
3namespace {
Anders Carlsson7ca46432009-12-05 17:04:47 +00004 struct A {
5 virtual void f() { }
6 };
Anders Carlsson7ca46432009-12-05 17:04:47 +00007}
8
Anders Carlsson152d4dc2009-12-05 22:19:10 +00009void f() { A b; }
10
11struct B {
12 B();
13 virtual void f();
14};
15
16B::B() { }
17
Anders Carlsson891c8b72009-12-05 22:24:38 +000018struct C {
19 C();
20 virtual void f() { }
21};
22
23C::C() { }
24
Anders Carlsson5794c972009-12-06 00:53:22 +000025struct D {
26 virtual void f();
27};
28
29void D::f() { }
30
Eli Friedman470fb732009-12-11 20:48:18 +000031static struct : D { } e;
32
Douglas Gregor074a2cf2010-01-05 21:40:05 +000033// The destructor is the key function.
Douglas Gregorbd6d6192010-01-05 19:06:31 +000034template<typename T>
35struct E {
36 virtual ~E();
37};
38
39template<typename T> E<T>::~E() { }
40
Douglas Gregor074a2cf2010-01-05 21:40:05 +000041// Anchor is the key function
Douglas Gregorbd6d6192010-01-05 19:06:31 +000042template<>
43struct E<char> {
44 virtual void anchor();
45};
46
47void E<char>::anchor() { }
48
49template struct E<short>;
50extern template struct E<int>;
51
52void use_E() {
53 E<int> ei;
54 (void)ei;
55 E<long> el;
56 (void)el;
57}
58
Douglas Gregor074a2cf2010-01-05 21:40:05 +000059// No key function
60template<typename T>
61struct F {
62 virtual void foo() { }
63};
64
65// No key function
66template<>
67struct F<char> {
68 virtual void foo() { }
69};
70
71template struct F<short>;
72extern template struct F<int>;
73
74void use_F(F<char> &fc) {
75 F<int> fi;
76 (void)fi;
77 F<long> fl;
78 (void)fl;
79 fc.foo();
80}
81
Anders Carlsson152d4dc2009-12-05 22:19:10 +000082// B has a key function that is not defined in this translation unit so its vtable
83// has external linkage.
84// CHECK: @_ZTV1B = external constant
85
Anders Carlsson891c8b72009-12-05 22:24:38 +000086// C has no key function, so its vtable should have weak_odr linkage.
Anders Carlsson31b7f522009-12-11 02:46:30 +000087// CHECK: @_ZTS1C = weak_odr constant
88// CHECK: @_ZTI1C = weak_odr constant
Anders Carlsson891c8b72009-12-05 22:24:38 +000089// CHECK: @_ZTV1C = weak_odr constant
90
Anders Carlsson5794c972009-12-06 00:53:22 +000091// D has a key function that is defined in this translation unit so its vtable is
92// defined in the translation unit.
Anders Carlsson31b7f522009-12-11 02:46:30 +000093// CHECK: @_ZTS1D = constant
94// CHECK: @_ZTI1D = constant
Anders Carlsson5794c972009-12-06 00:53:22 +000095// CHECK: @_ZTV1D = constant
96
Douglas Gregorbd6d6192010-01-05 19:06:31 +000097// E<char> is an explicit specialization with a key function defined
98// in this translation unit, so its vtable should have external
99// linkage.
Douglas Gregorc84622a2010-01-07 04:09:30 +0000100// CHECK: @_ZTS1EIcE = constant
101// CHECK: @_ZTI1EIcE = constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000102// CHECK: @_ZTV1EIcE = constant
103
104// E<short> is an explicit template instantiation with a key function
105// defined in this translation unit, so its vtable should have
106// weak_odr linkage.
Douglas Gregorc84622a2010-01-07 04:09:30 +0000107// CHECK: @_ZTS1EIsE = weak_odr constant
108// CHECK: @_ZTI1EIsE = weak_odr constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000109// CHECK: @_ZTV1EIsE = weak_odr constant
110
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000111// F<short> is an explicit template instantiation without a key
112// function, so its vtable should have weak_odr linkage
Douglas Gregorc84622a2010-01-07 04:09:30 +0000113// CHECK: @_ZTS1FIsE = weak_odr constant
114// CHECK: @_ZTI1FIsE = weak_odr constant
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000115// CHECK: @_ZTV1FIsE = weak_odr constant
116
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000117// E<long> is an implicit template instantiation with a key function
118// defined in this translation unit, so its vtable should have
119// weak_odr linkage.
Douglas Gregorc84622a2010-01-07 04:09:30 +0000120// CHECK: @_ZTS1EIlE = weak_odr constant
121// CHECK: @_ZTI1EIlE = weak_odr constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000122// CHECK: @_ZTV1EIlE = weak_odr constant
123
Eli Friedman470fb732009-12-11 20:48:18 +0000124// The anonymous struct for e has no linkage, so the vtable should have
125// internal linkage.
126// CHECK: @"_ZTS3$_0" = internal constant
127// CHECK: @"_ZTI3$_0" = internal constant
128// CHECK: @"_ZTV3$_0" = internal constant
129
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000130// F<long> is an implicit template instantiation with no key function,
131// so its vtable should have weak_odr linkage.
Douglas Gregorc84622a2010-01-07 04:09:30 +0000132// CHECK: @_ZTS1FIlE = weak_odr constant
133// CHECK: @_ZTI1FIlE = weak_odr constant
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000134// CHECK: @_ZTV1FIlE = weak_odr constant
135
136// F<int> is an explicit template instantiation declaration without a
137// key function, so its vtable should have weak_odr linkage.
Douglas Gregorc84622a2010-01-07 04:09:30 +0000138// CHECK: @_ZTS1FIiE = weak_odr constant
139// CHECK: @_ZTI1FIiE = weak_odr constant
Douglas Gregor1a78afb2010-01-06 04:50:56 +0000140// CHECK: @_ZTV1FIiE = weak_odr constant
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000141
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000142// E<int> is an explicit template instantiation declaration. It has a
Douglas Gregorc84622a2010-01-07 04:09:30 +0000143// key function that is not instantiated, so we should only reference
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000144// its vtable, not define it.
145// CHECK: @_ZTV1EIiE = external constant
146
Anders Carlsson152d4dc2009-12-05 22:19:10 +0000147// The A vtable should have internal linkage since it is inside an anonymous
148// namespace.
Anders Carlsson31b7f522009-12-11 02:46:30 +0000149// CHECK: @_ZTSN12_GLOBAL__N_11AE = internal constant
150// CHECK: @_ZTIN12_GLOBAL__N_11AE = internal constant
Anders Carlsson152d4dc2009-12-05 22:19:10 +0000151// CHECK: @_ZTVN12_GLOBAL__N_11AE = internal constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000152
153