// Set the right visibility.
CGM.setGlobalVisibility(VTable, RD);
+
+ // 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
+ 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);
+ }
}
llvm::GlobalVariable *
struct testc { virtual void a(); };
inline void testc::a() {}
-// Key functions with inline specifier (PR5705)
+// Functions with inline specifier are not key functions (PR5705)
struct testd { inline virtual void a(); };
void testd::a() {}
-// Key functions with inline specifier (PR5705)
+// Functions with inline specifier are not key functions (PR5705)
struct teste { inline virtual void a(); };
teste *testevar = new teste;
// CHECK: @_ZTV5testa = constant [3 x i8*] [i8* null
// CHECK: @_ZTV5testc = weak_odr constant [3 x i8*] [i8* null
// CHECK: @_ZTVN12_GLOBAL__N_15testgE = internal constant [3 x i8*] [i8* null
-// CHECK: @_ZTV5teste = weak_odr constant [3 x i8*] [i8* null
-// CHECK: @_ZTV5testb = weak_odr constant [3 x i8*] [i8* null
+// CHECK: @_ZTV5teste = weak_odr hidden constant [3 x i8*] [i8* null
+// CHECK: @_ZTV5testb = weak_odr hidden constant [3 x i8*] [i8* null
};
B::B() {}
+template class A<long>;
+
+extern template class A<short>;
+template class A<short>;
+
+
+// CHECK: @_ZTV1B = weak_odr hidden constant
+// CHECK: @_ZTV1AIlE = weak_odr constant
+// CHECK: @_ZTV1AIsE = weak_odr constant
// CHECK: @_ZTV1AIiE = weak_odr constant
// A does not have a key function, so the first constructor we emit should
// cause the vtable to be defined (without assertions.)
-// CHECK: @_ZTVN6PR56971AE = weak_odr constant
+// CHECK: @_ZTVN6PR56971AE = weak_odr hidden constant
A::A() { }
A::A(int) { }
}
// has external linkage.
// CHECK-1: @_ZTV1B = external constant
-// C has no key function, so its vtable should have weak_odr linkage.
-// CHECK-2: @_ZTV1C = weak_odr constant
+// C has no key function, so its vtable should have weak_odr linkage
+// and hidden visibility (rdar://problem/7523229).
+// CHECK-2: @_ZTV1C = weak_odr hidden constant
// CHECK-2: @_ZTS1C = weak_odr constant
// CHECK-2: @_ZTI1C = weak_odr constant