Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s |
Anders Carlsson | 7ca4643 | 2009-12-05 17:04:47 +0000 | [diff] [blame] | 2 | |
| 3 | namespace { |
Anders Carlsson | 7ca4643 | 2009-12-05 17:04:47 +0000 | [diff] [blame] | 4 | struct A { |
| 5 | virtual void f() { } |
| 6 | }; |
Anders Carlsson | 7ca4643 | 2009-12-05 17:04:47 +0000 | [diff] [blame] | 7 | } |
| 8 | |
Anders Carlsson | 152d4dc | 2009-12-05 22:19:10 +0000 | [diff] [blame] | 9 | void f() { A b; } |
| 10 | |
| 11 | struct B { |
| 12 | B(); |
| 13 | virtual void f(); |
| 14 | }; |
| 15 | |
| 16 | B::B() { } |
| 17 | |
Anders Carlsson | 891c8b7 | 2009-12-05 22:24:38 +0000 | [diff] [blame] | 18 | struct C { |
| 19 | C(); |
| 20 | virtual void f() { } |
| 21 | }; |
| 22 | |
| 23 | C::C() { } |
| 24 | |
Anders Carlsson | 5794c97 | 2009-12-06 00:53:22 +0000 | [diff] [blame] | 25 | struct D { |
| 26 | virtual void f(); |
| 27 | }; |
| 28 | |
| 29 | void D::f() { } |
| 30 | |
Eli Friedman | 470fb73 | 2009-12-11 20:48:18 +0000 | [diff] [blame] | 31 | static struct : D { } e; |
| 32 | |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 33 | // The destructor is the key function. |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 34 | template<typename T> |
| 35 | struct E { |
| 36 | virtual ~E(); |
| 37 | }; |
| 38 | |
| 39 | template<typename T> E<T>::~E() { } |
| 40 | |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 41 | // Anchor is the key function |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 42 | template<> |
| 43 | struct E<char> { |
| 44 | virtual void anchor(); |
| 45 | }; |
| 46 | |
| 47 | void E<char>::anchor() { } |
| 48 | |
| 49 | template struct E<short>; |
| 50 | extern template struct E<int>; |
| 51 | |
| 52 | void use_E() { |
| 53 | E<int> ei; |
| 54 | (void)ei; |
| 55 | E<long> el; |
| 56 | (void)el; |
| 57 | } |
| 58 | |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 59 | // No key function |
| 60 | template<typename T> |
| 61 | struct F { |
| 62 | virtual void foo() { } |
| 63 | }; |
| 64 | |
| 65 | // No key function |
| 66 | template<> |
| 67 | struct F<char> { |
| 68 | virtual void foo() { } |
| 69 | }; |
| 70 | |
| 71 | template struct F<short>; |
| 72 | extern template struct F<int>; |
| 73 | |
| 74 | void 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 Carlsson | 152d4dc | 2009-12-05 22:19:10 +0000 | [diff] [blame] | 82 | // 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 Carlsson | 891c8b7 | 2009-12-05 22:24:38 +0000 | [diff] [blame] | 86 | // C has no key function, so its vtable should have weak_odr linkage. |
Anders Carlsson | 31b7f52 | 2009-12-11 02:46:30 +0000 | [diff] [blame] | 87 | // CHECK: @_ZTS1C = weak_odr constant |
| 88 | // CHECK: @_ZTI1C = weak_odr constant |
Anders Carlsson | 891c8b7 | 2009-12-05 22:24:38 +0000 | [diff] [blame] | 89 | // CHECK: @_ZTV1C = weak_odr constant |
| 90 | |
Anders Carlsson | 5794c97 | 2009-12-06 00:53:22 +0000 | [diff] [blame] | 91 | // D has a key function that is defined in this translation unit so its vtable is |
| 92 | // defined in the translation unit. |
Anders Carlsson | 31b7f52 | 2009-12-11 02:46:30 +0000 | [diff] [blame] | 93 | // CHECK: @_ZTS1D = constant |
| 94 | // CHECK: @_ZTI1D = constant |
Anders Carlsson | 5794c97 | 2009-12-06 00:53:22 +0000 | [diff] [blame] | 95 | // CHECK: @_ZTV1D = constant |
| 96 | |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 97 | // 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 Gregor | c84622a | 2010-01-07 04:09:30 +0000 | [diff] [blame^] | 100 | // CHECK: @_ZTS1EIcE = constant |
| 101 | // CHECK: @_ZTI1EIcE = constant |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 102 | // 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 Gregor | c84622a | 2010-01-07 04:09:30 +0000 | [diff] [blame^] | 107 | // CHECK: @_ZTS1EIsE = weak_odr constant |
| 108 | // CHECK: @_ZTI1EIsE = weak_odr constant |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 109 | // CHECK: @_ZTV1EIsE = weak_odr constant |
| 110 | |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 111 | // F<short> is an explicit template instantiation without a key |
| 112 | // function, so its vtable should have weak_odr linkage |
Douglas Gregor | c84622a | 2010-01-07 04:09:30 +0000 | [diff] [blame^] | 113 | // CHECK: @_ZTS1FIsE = weak_odr constant |
| 114 | // CHECK: @_ZTI1FIsE = weak_odr constant |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 115 | // CHECK: @_ZTV1FIsE = weak_odr constant |
| 116 | |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 117 | // 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 Gregor | c84622a | 2010-01-07 04:09:30 +0000 | [diff] [blame^] | 120 | // CHECK: @_ZTS1EIlE = weak_odr constant |
| 121 | // CHECK: @_ZTI1EIlE = weak_odr constant |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 122 | // CHECK: @_ZTV1EIlE = weak_odr constant |
| 123 | |
Eli Friedman | 470fb73 | 2009-12-11 20:48:18 +0000 | [diff] [blame] | 124 | // 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 Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 130 | // F<long> is an implicit template instantiation with no key function, |
| 131 | // so its vtable should have weak_odr linkage. |
Douglas Gregor | c84622a | 2010-01-07 04:09:30 +0000 | [diff] [blame^] | 132 | // CHECK: @_ZTS1FIlE = weak_odr constant |
| 133 | // CHECK: @_ZTI1FIlE = weak_odr constant |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 134 | // 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 Gregor | c84622a | 2010-01-07 04:09:30 +0000 | [diff] [blame^] | 138 | // CHECK: @_ZTS1FIiE = weak_odr constant |
| 139 | // CHECK: @_ZTI1FIiE = weak_odr constant |
Douglas Gregor | 1a78afb | 2010-01-06 04:50:56 +0000 | [diff] [blame] | 140 | // CHECK: @_ZTV1FIiE = weak_odr constant |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 141 | |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 142 | // E<int> is an explicit template instantiation declaration. It has a |
Douglas Gregor | c84622a | 2010-01-07 04:09:30 +0000 | [diff] [blame^] | 143 | // key function that is not instantiated, so we should only reference |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 144 | // its vtable, not define it. |
| 145 | // CHECK: @_ZTV1EIiE = external constant |
| 146 | |
Anders Carlsson | 152d4dc | 2009-12-05 22:19:10 +0000 | [diff] [blame] | 147 | // The A vtable should have internal linkage since it is inside an anonymous |
| 148 | // namespace. |
Anders Carlsson | 31b7f52 | 2009-12-11 02:46:30 +0000 | [diff] [blame] | 149 | // CHECK: @_ZTSN12_GLOBAL__N_11AE = internal constant |
| 150 | // CHECK: @_ZTIN12_GLOBAL__N_11AE = internal constant |
Anders Carlsson | 152d4dc | 2009-12-05 22:19:10 +0000 | [diff] [blame] | 151 | // CHECK: @_ZTVN12_GLOBAL__N_11AE = internal constant |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 152 | |
| 153 | |