blob: a4ea2a19c23805ee9869ee3fccf8e9bba2d7146e [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 Carlssonc9b64ba2010-03-30 02:21:54 +000087// CHECK: @_ZTV1C = weak_odr constant
Anders Carlsson31b7f522009-12-11 02:46:30 +000088// CHECK: @_ZTS1C = weak_odr constant
89// CHECK: @_ZTI1C = weak_odr constant
Anders Carlsson891c8b72009-12-05 22:24:38 +000090
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 Carlssonc9b64ba2010-03-30 02:21:54 +000093// CHECK: @_ZTV1D = constant
Anders Carlsson31b7f522009-12-11 02:46:30 +000094// CHECK: @_ZTS1D = constant
95// CHECK: @_ZTI1D = constant
Anders Carlsson5794c972009-12-06 00:53:22 +000096
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.
Anders Carlssonc9b64ba2010-03-30 02:21:54 +0000100// CHECK: @_ZTV1EIcE = constant
Douglas Gregorc84622a2010-01-07 04:09:30 +0000101// CHECK: @_ZTS1EIcE = constant
102// CHECK: @_ZTI1EIcE = constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000103
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.
Anders Carlssonc9b64ba2010-03-30 02:21:54 +0000107// CHECK: @_ZTV1EIsE = weak_odr constant
Douglas Gregorc84622a2010-01-07 04:09:30 +0000108// CHECK: @_ZTS1EIsE = weak_odr constant
109// CHECK: @_ZTI1EIsE = weak_odr constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000110
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
Anders Carlssonc9b64ba2010-03-30 02:21:54 +0000113// CHECK: @_ZTV1FIsE = weak_odr constant
Douglas Gregorc84622a2010-01-07 04:09:30 +0000114// CHECK: @_ZTS1FIsE = weak_odr constant
115// CHECK: @_ZTI1FIsE = weak_odr constant
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000116
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.
Anders Carlssonc9b64ba2010-03-30 02:21:54 +0000120// CHECK: @_ZTV1EIlE = weak_odr constant
Douglas Gregorc84622a2010-01-07 04:09:30 +0000121// CHECK: @_ZTS1EIlE = weak_odr constant
122// CHECK: @_ZTI1EIlE = weak_odr constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000123
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000124// F<long> is an implicit template instantiation with no key function,
125// so its vtable should have weak_odr linkage.
Anders Carlssonc9b64ba2010-03-30 02:21:54 +0000126// CHECK: @_ZTV1FIlE = weak_odr constant
Douglas Gregorc84622a2010-01-07 04:09:30 +0000127// CHECK: @_ZTS1FIlE = weak_odr constant
128// CHECK: @_ZTI1FIlE = weak_odr constant
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000129
130// F<int> is an explicit template instantiation declaration without a
131// key function, so its vtable should have weak_odr linkage.
Anders Carlssonc9b64ba2010-03-30 02:21:54 +0000132// CHECK: @_ZTV1FIiE = weak_odr constant
Douglas Gregorc84622a2010-01-07 04:09:30 +0000133// CHECK: @_ZTS1FIiE = weak_odr constant
134// CHECK: @_ZTI1FIiE = weak_odr constant
Douglas Gregor074a2cf2010-01-05 21:40:05 +0000135
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000136// E<int> is an explicit template instantiation declaration. It has a
Douglas Gregorc84622a2010-01-07 04:09:30 +0000137// key function that is not instantiated, so we should only reference
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000138// its vtable, not define it.
139// CHECK: @_ZTV1EIiE = external constant
140
Eli Friedman6c6bda32010-01-08 00:50:11 +0000141// The anonymous struct for e has no linkage, so the vtable should have
142// internal linkage.
Anders Carlssonc9b64ba2010-03-30 02:21:54 +0000143// CHECK: @"_ZTV3$_0" = internal constant
Eli Friedman6c6bda32010-01-08 00:50:11 +0000144// CHECK: @"_ZTS3$_0" = internal constant
145// CHECK: @"_ZTI3$_0" = internal constant
Eli Friedman6c6bda32010-01-08 00:50:11 +0000146
Anders Carlsson152d4dc2009-12-05 22:19:10 +0000147// The A vtable should have internal linkage since it is inside an anonymous
148// namespace.
Anders Carlssonc9b64ba2010-03-30 02:21:54 +0000149// CHECK: @_ZTVN12_GLOBAL__N_11AE = internal constant
Anders Carlsson31b7f522009-12-11 02:46:30 +0000150// CHECK: @_ZTSN12_GLOBAL__N_11AE = internal constant
151// CHECK: @_ZTIN12_GLOBAL__N_11AE = internal constant
Douglas Gregorbd6d6192010-01-05 19:06:31 +0000152
153