// It's okay to have multiple copies of a vtable, so don't make the
// dynamic linker unique them. Suppress this optimization if it's
- // possible that there might be unresolved references elsewhere,
- // which can happen if
- // - there's a key function and the vtable is getting emitted weak
- // anyway for whatever reason
- // - there might be an explicit instantiation declaration somewhere,
- // i.e. if it's a template at all
+ // possible that there might be unresolved references elsewhere
+ // which can only be resolved by this emission.
if (Linkage == llvm::GlobalVariable::WeakODRLinkage &&
VTable->getVisibility() == llvm::GlobalVariable::DefaultVisibility &&
- !RD->hasAttr<VisibilityAttr>() &&
- RD->getTemplateSpecializationKind() == TSK_Undeclared &&
- !CGM.Context.getKeyFunction(RD)) {
- VTable->setVisibility(llvm::GlobalVariable::HiddenVisibility);
+ !RD->hasAttr<VisibilityAttr>()) {
+ switch (RD->getTemplateSpecializationKind()) {
+
+ // Every use of a non-template or explicitly-specialized class's
+ // vtable has to emit it.
+ case TSK_ExplicitSpecialization:
+ case TSK_Undeclared:
+ // Implicit instantiations can ignore the possibility of an
+ // explicit instantiation declaration because there necessarily
+ // must be an EI definition somewhere with default visibility.
+ case TSK_ImplicitInstantiation:
+ // If there's a key function, there may be translation units
+ // that don't have the key function's definition.
+ if (!CGM.Context.getKeyFunction(RD))
+ // Otherwise, drop the visibility to hidden.
+ VTable->setVisibility(llvm::GlobalValue::HiddenVisibility);
+ break;
+
+ // We have to disable the optimization if this is an EI definition
+ // because there might be EI declarations in other shared objects.
+ case TSK_ExplicitInstantiationDefinition:
+ case TSK_ExplicitInstantiationDeclaration:
+ break;
+ }
}
}
// Check mangling of Vtables, VTTs, and construction vtables that
// involve standard substitutions.
-// CHECK: @_ZTVSd = weak_odr constant
+// CHECK: @_ZTVSd = weak_odr hidden constant
// CHECK: @_ZTCSd0_Si = internal constant
// CHECK: @_ZTCSd16_So = internal constant
// CHECK: @_ZTTSd = weak_odr constant
-// CHECK: @_ZTVSo = weak_odr constant
+// CHECK: @_ZTVSo = weak_odr hidden constant
// CHECK: @_ZTTSo = weak_odr constant
-// CHECK: @_ZTVSi = weak_odr constant
+// CHECK: @_ZTVSi = weak_odr hidden constant
// CHECK: @_ZTTSi = weak_odr constant
namespace std {
struct A { A(); };
// CHECK: @_ZTV1B = weak_odr hidden constant
// CHECK: @_ZTV1AIlE = weak_odr constant
// CHECK: @_ZTV1AIsE = weak_odr constant
-// CHECK: @_ZTV1AIiE = weak_odr constant
+// CHECK: @_ZTV1AIiE = weak_odr hidden constant
// RUN: FileCheck --check-prefix=CHECK-10 %s < %t
// RUN: FileCheck --check-prefix=CHECK-11 %s < %t
// RUN: FileCheck --check-prefix=CHECK-12 %s < %t
+// RUN: FileCheck --check-prefix=CHECK-13 %s < %t
namespace {
struct A {
template struct F<short>;
extern template struct F<int>;
-void use_F(F<char> &fc) {
+void use_F() {
+ F<char> fc;
+ fc.foo();
F<int> fi;
fi.foo();
F<long> fl;
(void)fl;
- fc.foo();
}
// B has a key function that is not defined in this translation unit so its vtable
// CHECK-7: @_ZTI1EIlE = weak_odr constant
// F<long> is an implicit template instantiation with no key function,
-// so its vtable should have weak_odr linkage.
-// CHECK-8: @_ZTV1FIlE = weak_odr constant
+// so its vtable should have weak_odr linkage and hidden visibility.
+// CHECK-8: @_ZTV1FIlE = weak_odr hidden constant
// CHECK-8: @_ZTS1FIlE = weak_odr constant
// CHECK-8: @_ZTI1FIlE = weak_odr constant
// CHECK-12: @_ZTSN12_GLOBAL__N_11AE = internal constant
// CHECK-12: @_ZTIN12_GLOBAL__N_11AE = internal constant
+// F<char> is an explicit specialization without a key function, so
+// its vtable should have weak_odr linkage and hidden visibility.
+// CHECK-13: @_ZTV1FIcE = weak_odr hidden constant
+// CHECK-13: @_ZTS1FIcE = weak_odr constant
+// CHECK-13: @_ZTI1FIcE = weak_odr constant
+
// RUN: FileCheck --check-prefix=CHECK-G %s < %t
//
// CHECK-G: @_ZTV1GIiE = weak_odr constant