Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 1 | // 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 Carlsson | 7ca4643 | 2009-12-05 17:04:47 +0000 | [diff] [blame] | 14 | |
| 15 | namespace { |
Anders Carlsson | 7ca4643 | 2009-12-05 17:04:47 +0000 | [diff] [blame] | 16 | struct A { |
| 17 | virtual void f() { } |
| 18 | }; |
Anders Carlsson | 7ca4643 | 2009-12-05 17:04:47 +0000 | [diff] [blame] | 19 | } |
| 20 | |
Anders Carlsson | 152d4dc | 2009-12-05 22:19:10 +0000 | [diff] [blame] | 21 | void f() { A b; } |
| 22 | |
| 23 | struct B { |
| 24 | B(); |
| 25 | virtual void f(); |
| 26 | }; |
| 27 | |
| 28 | B::B() { } |
| 29 | |
Anders Carlsson | 891c8b7 | 2009-12-05 22:24:38 +0000 | [diff] [blame] | 30 | struct C { |
| 31 | C(); |
| 32 | virtual void f() { } |
| 33 | }; |
| 34 | |
| 35 | C::C() { } |
| 36 | |
Anders Carlsson | 5794c97 | 2009-12-06 00:53:22 +0000 | [diff] [blame] | 37 | struct D { |
| 38 | virtual void f(); |
| 39 | }; |
| 40 | |
| 41 | void D::f() { } |
| 42 | |
Eli Friedman | 470fb73 | 2009-12-11 20:48:18 +0000 | [diff] [blame] | 43 | static struct : D { } e; |
| 44 | |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 45 | // The destructor is the key function. |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 46 | template<typename T> |
| 47 | struct E { |
| 48 | virtual ~E(); |
| 49 | }; |
| 50 | |
| 51 | template<typename T> E<T>::~E() { } |
| 52 | |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 53 | // Anchor is the key function |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 54 | template<> |
| 55 | struct E<char> { |
| 56 | virtual void anchor(); |
| 57 | }; |
| 58 | |
| 59 | void E<char>::anchor() { } |
| 60 | |
| 61 | template struct E<short>; |
| 62 | extern template struct E<int>; |
| 63 | |
| 64 | void use_E() { |
| 65 | E<int> ei; |
| 66 | (void)ei; |
| 67 | E<long> el; |
| 68 | (void)el; |
| 69 | } |
| 70 | |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 71 | // No key function |
| 72 | template<typename T> |
| 73 | struct F { |
| 74 | virtual void foo() { } |
| 75 | }; |
| 76 | |
| 77 | // No key function |
| 78 | template<> |
| 79 | struct F<char> { |
| 80 | virtual void foo() { } |
| 81 | }; |
| 82 | |
| 83 | template struct F<short>; |
| 84 | extern template struct F<int>; |
| 85 | |
| 86 | void use_F(F<char> &fc) { |
| 87 | F<int> fi; |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 88 | fi.foo(); |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 89 | F<long> fl; |
| 90 | (void)fl; |
| 91 | fc.foo(); |
| 92 | } |
| 93 | |
Anders Carlsson | 152d4dc | 2009-12-05 22:19:10 +0000 | [diff] [blame] | 94 | // B has a key function that is not defined in this translation unit so its vtable |
| 95 | // has external linkage. |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 96 | // CHECK-1: @_ZTV1B = external constant |
Anders Carlsson | 152d4dc | 2009-12-05 22:19:10 +0000 | [diff] [blame] | 97 | |
Anders Carlsson | 891c8b7 | 2009-12-05 22:24:38 +0000 | [diff] [blame] | 98 | // C has no key function, so its vtable should have weak_odr linkage. |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 99 | // CHECK-2: @_ZTV1C = weak_odr constant |
| 100 | // CHECK-2: @_ZTS1C = weak_odr constant |
| 101 | // CHECK-2: @_ZTI1C = weak_odr constant |
Anders Carlsson | 891c8b7 | 2009-12-05 22:24:38 +0000 | [diff] [blame] | 102 | |
Anders Carlsson | 5794c97 | 2009-12-06 00:53:22 +0000 | [diff] [blame] | 103 | // D has a key function that is defined in this translation unit so its vtable is |
| 104 | // defined in the translation unit. |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 105 | // CHECK-3: @_ZTV1D = constant |
| 106 | // CHECK-3: @_ZTS1D = constant |
| 107 | // CHECK-3: @_ZTI1D = constant |
Anders Carlsson | 5794c97 | 2009-12-06 00:53:22 +0000 | [diff] [blame] | 108 | |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 109 | // 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 Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 112 | // CHECK-4: @_ZTV1EIcE = constant |
| 113 | // CHECK-4: @_ZTS1EIcE = constant |
| 114 | // CHECK-4: @_ZTI1EIcE = constant |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 115 | |
| 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 Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 119 | // CHECK-5: @_ZTV1EIsE = weak_odr constant |
| 120 | // CHECK-5: @_ZTS1EIsE = weak_odr constant |
| 121 | // CHECK-5: @_ZTI1EIsE = weak_odr constant |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 122 | |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 123 | // F<short> is an explicit template instantiation without a key |
| 124 | // function, so its vtable should have weak_odr linkage |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 125 | // CHECK-6: @_ZTV1FIsE = weak_odr constant |
| 126 | // CHECK-6: @_ZTS1FIsE = weak_odr constant |
| 127 | // CHECK-6: @_ZTI1FIsE = weak_odr constant |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 128 | |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 129 | // 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 Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 132 | // CHECK-7: @_ZTV1EIlE = weak_odr constant |
| 133 | // CHECK-7: @_ZTS1EIlE = weak_odr constant |
| 134 | // CHECK-7: @_ZTI1EIlE = weak_odr constant |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 135 | |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 136 | // F<long> is an implicit template instantiation with no key function, |
| 137 | // so its vtable should have weak_odr linkage. |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 138 | // CHECK-8: @_ZTV1FIlE = weak_odr constant |
| 139 | // CHECK-8: @_ZTS1FIlE = weak_odr constant |
| 140 | // CHECK-8: @_ZTI1FIlE = weak_odr constant |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 141 | |
| 142 | // F<int> is an explicit template instantiation declaration without a |
Rafael Espindola | 35d6461 | 2010-04-03 04:26:42 +0000 | [diff] [blame] | 143 | // key function, so its vtable should have external linkage. |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 144 | // CHECK-9: @_ZTV1FIiE = external constant |
Douglas Gregor | 074a2cf | 2010-01-05 21:40:05 +0000 | [diff] [blame] | 145 | |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 146 | // E<int> is an explicit template instantiation declaration. It has a |
Douglas Gregor | c84622a | 2010-01-07 04:09:30 +0000 | [diff] [blame] | 147 | // key function that is not instantiated, so we should only reference |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 148 | // its vtable, not define it. |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 149 | // CHECK-10: @_ZTV1EIiE = external constant |
Douglas Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 150 | |
Eli Friedman | 6c6bda3 | 2010-01-08 00:50:11 +0000 | [diff] [blame] | 151 | // The anonymous struct for e has no linkage, so the vtable should have |
| 152 | // internal linkage. |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 153 | // CHECK-11: @"_ZTV3$_0" = internal constant |
| 154 | // CHECK-11: @"_ZTS3$_0" = internal constant |
| 155 | // CHECK-11: @"_ZTI3$_0" = internal constant |
Eli Friedman | 6c6bda3 | 2010-01-08 00:50:11 +0000 | [diff] [blame] | 156 | |
Anders Carlsson | 152d4dc | 2009-12-05 22:19:10 +0000 | [diff] [blame] | 157 | // The A vtable should have internal linkage since it is inside an anonymous |
| 158 | // namespace. |
Douglas Gregor | 6fb745b | 2010-05-13 16:44:06 +0000 | [diff] [blame^] | 159 | // 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 Gregor | bd6d619 | 2010-01-05 19:06:31 +0000 | [diff] [blame] | 162 | |
| 163 | |