1 // RUN: %clang_cc1 %s -triple=x86_64-pc-linux -emit-llvm -o %t
2 // RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -disable-llvm-optzns -O3 -emit-llvm -o %t.opt
3 // RUN: FileCheck --check-prefix=CHECK %s < %t
4 // RUN: FileCheck --check-prefix=CHECK-OPT %s < %t.opt
21 struct C : virtual B {
34 static struct : D { } e;
36 // The destructor is the key function.
42 template<typename T> E<T>::~E() { }
44 // Anchor is the key function
47 virtual void anchor();
50 void E<char>::anchor() { }
52 template struct E<short>;
53 extern template struct E<int>;
65 virtual void foo() { }
71 virtual void foo() { }
74 template struct F<short>;
75 extern template struct F<int>;
86 // B has a key function that is not defined in this translation unit so its vtable
87 // has external linkage.
88 // CHECK-DAG: @_ZTV1B = external unnamed_addr constant
90 // C has no key function, so its vtable should have weak_odr linkage
91 // and hidden visibility (rdar://problem/7523229).
92 // CHECK-DAG: @_ZTV1C = linkonce_odr unnamed_addr constant {{.*}}, comdat,
93 // CHECK-DAG: @_ZTS1C = linkonce_odr constant {{.*}}, comdat{{$}}
94 // CHECK-DAG: @_ZTI1C = linkonce_odr constant {{.*}}, comdat{{$}}
95 // CHECK-DAG: @_ZTT1C = linkonce_odr unnamed_addr constant {{.*}}, comdat{{$}}
97 // D has a key function that is defined in this translation unit so its vtable is
98 // defined in the translation unit.
99 // CHECK-DAG: @_ZTV1D = unnamed_addr constant
100 // CHECK-DAG: @_ZTS1D = constant
101 // CHECK-DAG: @_ZTI1D = constant
103 // E<char> is an explicit specialization with a key function defined
104 // in this translation unit, so its vtable should have external
106 // CHECK-DAG: @_ZTV1EIcE = unnamed_addr constant
107 // CHECK-DAG: @_ZTS1EIcE = constant
108 // CHECK-DAG: @_ZTI1EIcE = constant
110 // E<short> is an explicit template instantiation with a key function
111 // defined in this translation unit, so its vtable should have
113 // CHECK-DAG: @_ZTV1EIsE = weak_odr unnamed_addr constant {{.*}}, comdat,
114 // CHECK-DAG: @_ZTS1EIsE = weak_odr constant {{.*}}, comdat{{$}}
115 // CHECK-DAG: @_ZTI1EIsE = weak_odr constant {{.*}}, comdat{{$}}
117 // F<short> is an explicit template instantiation without a key
118 // function, so its vtable should have weak_odr linkage
119 // CHECK-DAG: @_ZTV1FIsE = weak_odr unnamed_addr constant {{.*}}, comdat,
120 // CHECK-DAG: @_ZTS1FIsE = weak_odr constant {{.*}}, comdat{{$}}
121 // CHECK-DAG: @_ZTI1FIsE = weak_odr constant {{.*}}, comdat{{$}}
123 // E<long> is an implicit template instantiation with a key function
124 // defined in this translation unit, so its vtable should have
125 // linkonce_odr linkage.
126 // CHECK-DAG: @_ZTV1EIlE = linkonce_odr unnamed_addr constant {{.*}}, comdat,
127 // CHECK-DAG: @_ZTS1EIlE = linkonce_odr constant {{.*}}, comdat{{$}}
128 // CHECK-DAG: @_ZTI1EIlE = linkonce_odr constant {{.*}}, comdat{{$}}
130 // F<long> is an implicit template instantiation with no key function,
131 // so its vtable should have linkonce_odr linkage.
132 // CHECK-DAG: @_ZTV1FIlE = linkonce_odr unnamed_addr constant {{.*}}, comdat,
133 // CHECK-DAG: @_ZTS1FIlE = linkonce_odr constant {{.*}}, comdat{{$}}
134 // CHECK-DAG: @_ZTI1FIlE = linkonce_odr constant {{.*}}, comdat{{$}}
136 // F<int> is an explicit template instantiation declaration without a
137 // key function, so its vtable should have external linkage.
138 // CHECK-DAG: @_ZTV1FIiE = external unnamed_addr constant
139 // CHECK-OPT-DAG: @_ZTV1FIiE = external unnamed_addr constant
141 // E<int> is an explicit template instantiation declaration. It has a
142 // key function that is not instantiated, so we should only reference
143 // its vtable, not define it.
144 // CHECK-DAG: @_ZTV1EIiE = external unnamed_addr constant
145 // CHECK-OPT-DAG: @_ZTV1EIiE = external unnamed_addr constant
147 // The anonymous struct for e has no linkage, so the vtable should have
149 // CHECK-DAG: @"_ZTV3$_0" = internal unnamed_addr constant
150 // CHECK-DAG: @"_ZTS3$_0" = internal constant
151 // CHECK-DAG: @"_ZTI3$_0" = internal constant
153 // The A vtable should have internal linkage since it is inside an anonymous
155 // CHECK-DAG: @_ZTVN12_GLOBAL__N_11AE = internal unnamed_addr constant
156 // CHECK-DAG: @_ZTSN12_GLOBAL__N_11AE = internal constant
157 // CHECK-DAG: @_ZTIN12_GLOBAL__N_11AE = internal constant
159 // F<char> is an explicit specialization without a key function, so
160 // its vtable should have linkonce_odr linkage.
161 // CHECK-DAG: @_ZTV1FIcE = linkonce_odr unnamed_addr constant {{.*}}, comdat,
162 // CHECK-DAG: @_ZTS1FIcE = linkonce_odr constant {{.*}}, comdat{{$}}
163 // CHECK-DAG: @_ZTI1FIcE = linkonce_odr constant {{.*}}, comdat{{$}}
165 // CHECK-DAG: @_ZTV1GIiE = linkonce_odr unnamed_addr constant {{.*}}, comdat,
166 template <typename T>
175 template <typename T>
177 void G_f0() { new G<int>(); }
179 // H<int> has a key function without a body but it's a template instantiation
180 // so its VTable must be emitted.
181 // CHECK-DAG: @_ZTV1HIiE = linkonce_odr unnamed_addr constant {{.*}}, comdat,
182 template <typename T>
192 // I<int> has an explicit instantiation declaration and needs a VTT and
193 // construction vtables.
195 // CHECK-DAG: @_ZTV1IIiE = external unnamed_addr constant
196 // CHECK-DAG: @_ZTT1IIiE = external unnamed_addr constant
197 // CHECK-NOT: @_ZTC1IIiE
199 // CHECK-OPT-DAG: @_ZTV1IIiE = external unnamed_addr constant
200 // CHECK-OPT-DAG: @_ZTT1IIiE = external unnamed_addr constant
201 struct VBase1 { virtual void f(); }; struct VBase2 : virtual VBase1 {};
203 struct I : VBase2 {};
204 extern template struct I<int>;