blob: 5738007041830c9ff7ab879f067856cd6eeea501 [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.
100// CHECK: @_ZTV1EIcE = constant
101
102// E<short> is an explicit template instantiation with a key function
103// defined in this translation unit, so its vtable should have
104// weak_odr linkage.
105// CHECK: @_ZTV1EIsE = weak_odr constant
106
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000107// F<short> is an explicit template instantiation without a key
108// function, so its vtable should have weak_odr linkage
109// CHECK: @_ZTV1FIsE = weak_odr constant
110
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000111// E<long> is an implicit template instantiation with a key function
112// defined in this translation unit, so its vtable should have
113// weak_odr linkage.
114// CHECK: @_ZTV1EIlE = weak_odr constant
115
Eli Friedman470fb732009-12-11 20:48:18 +0000116// The anonymous struct for e has no linkage, so the vtable should have
117// internal linkage.
118// CHECK: @"_ZTS3$_0" = internal constant
119// CHECK: @"_ZTI3$_0" = internal constant
120// CHECK: @"_ZTV3$_0" = internal constant
121
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000122// F<long> is an implicit template instantiation with no key function,
123// so its vtable should have weak_odr linkage.
124// CHECK: @_ZTV1FIlE = weak_odr constant
125
126// F<int> is an explicit template instantiation declaration without a
127// key function, so its vtable should have weak_odr linkage.
128// CHECK: @_ZTV1FIiE = available_externally constant
129
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000130// E<int> is an explicit template instantiation declaration. It has a
131// key function that is not instantiation, so we should only reference
132// its vtable, not define it.
133// CHECK: @_ZTV1EIiE = external constant
134
Anders Carlsson152d4dc2009-12-05 22:19:10 +0000135// The A vtable should have internal linkage since it is inside an anonymous
136// namespace.
Anders Carlsson31b7f522009-12-11 02:46:30 +0000137// CHECK: @_ZTSN12_GLOBAL__N_11AE = internal constant
138// CHECK: @_ZTIN12_GLOBAL__N_11AE = internal constant
Anders Carlsson152d4dc2009-12-05 22:19:10 +0000139// CHECK: @_ZTVN12_GLOBAL__N_11AE = internal constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000140
141