From 5674c644cfce28584637cb028379f88c67490bc2 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 11 Jan 2011 21:10:26 +0000 Subject: [PATCH] Add unnamed_addr to vtables. llvm-svn: 123272 --- clang/lib/CodeGen/CGVTables.cpp | 7 ++-- clang/test/CodeGenCXX/key-function-vtable.cpp | 12 +++---- clang/test/CodeGenCXX/mangle-subst-std.cpp | 6 ++-- .../CodeGenCXX/template-instantiation.cpp | 2 +- .../test/CodeGenCXX/virt-template-vtable.cpp | 8 ++--- clang/test/CodeGenCXX/visibility.cpp | 4 +-- clang/test/CodeGenCXX/vtable-key-function.cpp | 2 +- clang/test/CodeGenCXX/vtable-linkage.cpp | 36 +++++++++---------- 8 files changed, 40 insertions(+), 37 deletions(-) diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index ad648c62f565..ff65e583bb94 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/lib/CodeGen/CGVTables.cpp @@ -2979,8 +2979,11 @@ llvm::GlobalVariable *CodeGenVTables::GetAddrOfVTable(const CXXRecordDecl *RD) { llvm::ArrayType *ArrayType = llvm::ArrayType::get(Int8PtrTy, getNumVTableComponents(RD)); - return GetGlobalVariable(CGM.getModule(), Name, ArrayType, - llvm::GlobalValue::ExternalLinkage); + llvm::GlobalVariable *GV = + GetGlobalVariable(CGM.getModule(), Name, ArrayType, + llvm::GlobalValue::ExternalLinkage); + GV->setUnnamedAddr(true); + return GV; } void diff --git a/clang/test/CodeGenCXX/key-function-vtable.cpp b/clang/test/CodeGenCXX/key-function-vtable.cpp index 15c058da9460..d8f10d453272 100644 --- a/clang/test/CodeGenCXX/key-function-vtable.cpp +++ b/clang/test/CodeGenCXX/key-function-vtable.cpp @@ -43,9 +43,9 @@ void use_X1(X1 *x1) { x1->f(); } // FIXME: The checks are extremely difficult to get right when the globals // aren't alphabetized -// CHECK: @_ZTV2X1 = weak_odr constant -// 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: @_ZTV2X1 = weak_odr unnamed_addr constant +// CHECK: @_ZTV5testa = unnamed_addr constant [3 x i8*] [i8* null +// CHECK: @_ZTV5testc = weak_odr unnamed_addr constant [3 x i8*] [i8* null +// CHECK: @_ZTVN12_GLOBAL__N_15testgE = internal unnamed_addr constant [3 x i8*] [i8* null +// CHECK: @_ZTV5teste = weak_odr unnamed_addr constant [3 x i8*] [i8* null +// CHECK: @_ZTV5testb = weak_odr unnamed_addr constant [3 x i8*] [i8* null diff --git a/clang/test/CodeGenCXX/mangle-subst-std.cpp b/clang/test/CodeGenCXX/mangle-subst-std.cpp index 15e88d157e59..d35bf9cc7f97 100644 --- a/clang/test/CodeGenCXX/mangle-subst-std.cpp +++ b/clang/test/CodeGenCXX/mangle-subst-std.cpp @@ -3,13 +3,13 @@ // Check mangling of Vtables, VTTs, and construction vtables that // involve standard substitutions. -// CHECK: @_ZTVSd = weak_odr constant +// CHECK: @_ZTVSd = weak_odr unnamed_addr 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 unnamed_addr constant // CHECK: @_ZTTSo = weak_odr constant -// CHECK: @_ZTVSi = weak_odr constant +// CHECK: @_ZTVSi = weak_odr unnamed_addr constant // CHECK: @_ZTTSi = weak_odr constant namespace std { struct A { A(); }; diff --git a/clang/test/CodeGenCXX/template-instantiation.cpp b/clang/test/CodeGenCXX/template-instantiation.cpp index 89ad7e78efdf..1ccf24fee4cd 100644 --- a/clang/test/CodeGenCXX/template-instantiation.cpp +++ b/clang/test/CodeGenCXX/template-instantiation.cpp @@ -2,7 +2,7 @@ // CHECK-NOT: @_ZTVN5test118stdio_sync_filebufIwEE = constant // CHECK-NOT: _ZTVN5test315basic_fstreamXXIcEE -// CHECK: @_ZTVN5test018stdio_sync_filebufIwEE = constant +// CHECK: @_ZTVN5test018stdio_sync_filebufIwEE = unnamed_addr constant // CHECK-NOT: _ZTVN5test31SIiEE // CHECK-NOT: _ZTSN5test31SIiEE diff --git a/clang/test/CodeGenCXX/virt-template-vtable.cpp b/clang/test/CodeGenCXX/virt-template-vtable.cpp index d60cfb9043ac..b2e7bdaf3a00 100644 --- a/clang/test/CodeGenCXX/virt-template-vtable.cpp +++ b/clang/test/CodeGenCXX/virt-template-vtable.cpp @@ -16,7 +16,7 @@ extern template class A; template class A; -// CHECK: @_ZTV1B = weak_odr constant -// CHECK: @_ZTV1AIlE = weak_odr constant -// CHECK: @_ZTV1AIsE = weak_odr constant -// CHECK: @_ZTV1AIiE = weak_odr constant +// CHECK: @_ZTV1B = weak_odr unnamed_addr constant +// CHECK: @_ZTV1AIlE = weak_odr unnamed_addr constant +// CHECK: @_ZTV1AIsE = weak_odr unnamed_addr constant +// CHECK: @_ZTV1AIiE = weak_odr unnamed_addr constant diff --git a/clang/test/CodeGenCXX/visibility.cpp b/clang/test/CodeGenCXX/visibility.cpp index 38c554cd7282..73e2cd8576cc 100644 --- a/clang/test/CodeGenCXX/visibility.cpp +++ b/clang/test/CodeGenCXX/visibility.cpp @@ -27,8 +27,8 @@ // CHECK-HIDDEN: @_ZZN6Test193fooIiEEvvE1a = linkonce_odr hidden global // CHECK-HIDDEN: @_ZGVZN6Test193fooIiEEvvE1a = linkonce_odr hidden global i64 // CHECK-HIDDEN: @_ZTTN6Test161AIcEE = external constant -// CHECK-HIDDEN: @_ZTVN6Test161AIcEE = external constant -// CHECK: @_ZTVN5Test63fooE = weak_odr hidden constant +// CHECK-HIDDEN: @_ZTVN6Test161AIcEE = external unnamed_addr constant +// CHECK: @_ZTVN5Test63fooE = weak_odr hidden unnamed_addr constant namespace Test1 { // CHECK: define hidden void @_ZN5Test11fEv diff --git a/clang/test/CodeGenCXX/vtable-key-function.cpp b/clang/test/CodeGenCXX/vtable-key-function.cpp index 97a546f8c932..a9e4513b1647 100644 --- a/clang/test/CodeGenCXX/vtable-key-function.cpp +++ b/clang/test/CodeGenCXX/vtable-key-function.cpp @@ -9,7 +9,7 @@ struct A { // 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 unnamed_addr constant A::A() { } A::A(int) { } } diff --git a/clang/test/CodeGenCXX/vtable-linkage.cpp b/clang/test/CodeGenCXX/vtable-linkage.cpp index 265126882a1f..137ddb3cae34 100644 --- a/clang/test/CodeGenCXX/vtable-linkage.cpp +++ b/clang/test/CodeGenCXX/vtable-linkage.cpp @@ -99,92 +99,92 @@ void use_F() { // B has a key function that is not defined in this translation unit so its vtable // has external linkage. -// CHECK-1: @_ZTV1B = external constant +// CHECK-1: @_ZTV1B = external unnamed_addr 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 constant +// CHECK-2: @_ZTV1C = weak_odr unnamed_addr constant // CHECK-2: @_ZTS1C = weak_odr constant // CHECK-2: @_ZTI1C = weak_odr constant -// CHECK-2-HIDDEN: @_ZTV1C = weak_odr hidden constant +// CHECK-2-HIDDEN: @_ZTV1C = weak_odr hidden unnamed_addr constant // CHECK-2-HIDDEN: @_ZTS1C = weak_odr constant // CHECK-2-HIDDEN: @_ZTI1C = weak_odr hidden constant // D has a key function that is defined in this translation unit so its vtable is // defined in the translation unit. -// CHECK-3: @_ZTV1D = constant +// CHECK-3: @_ZTV1D = unnamed_addr constant // CHECK-3: @_ZTS1D = constant // CHECK-3: @_ZTI1D = constant // E is an explicit specialization with a key function defined // in this translation unit, so its vtable should have external // linkage. -// CHECK-4: @_ZTV1EIcE = constant +// CHECK-4: @_ZTV1EIcE = unnamed_addr constant // CHECK-4: @_ZTS1EIcE = constant // CHECK-4: @_ZTI1EIcE = constant // E is an explicit template instantiation with a key function // defined in this translation unit, so its vtable should have // weak_odr linkage. -// CHECK-5: @_ZTV1EIsE = weak_odr constant +// CHECK-5: @_ZTV1EIsE = weak_odr unnamed_addr constant // CHECK-5: @_ZTS1EIsE = weak_odr constant // CHECK-5: @_ZTI1EIsE = weak_odr constant -// CHECK-5-HIDDEN: @_ZTV1EIsE = weak_odr constant +// CHECK-5-HIDDEN: @_ZTV1EIsE = weak_odr unnamed_addr constant // CHECK-5-HIDDEN: @_ZTS1EIsE = weak_odr constant // CHECK-5-HIDDEN: @_ZTI1EIsE = weak_odr constant // F is an explicit template instantiation without a key // function, so its vtable should have weak_odr linkage -// CHECK-6: @_ZTV1FIsE = weak_odr constant +// CHECK-6: @_ZTV1FIsE = weak_odr unnamed_addr constant // CHECK-6: @_ZTS1FIsE = weak_odr constant // CHECK-6: @_ZTI1FIsE = weak_odr constant -// CHECK-6-HIDDEN: @_ZTV1FIsE = weak_odr constant +// CHECK-6-HIDDEN: @_ZTV1FIsE = weak_odr unnamed_addr constant // CHECK-6-HIDDEN: @_ZTS1FIsE = weak_odr constant // CHECK-6-HIDDEN: @_ZTI1FIsE = weak_odr constant // E is an implicit template instantiation with a key function // defined in this translation unit, so its vtable should have // weak_odr linkage. -// CHECK-7: @_ZTV1EIlE = weak_odr constant +// CHECK-7: @_ZTV1EIlE = weak_odr unnamed_addr constant // CHECK-7: @_ZTS1EIlE = weak_odr constant // CHECK-7: @_ZTI1EIlE = weak_odr constant // F is an implicit template instantiation with no key function, // so its vtable should have weak_odr linkage. -// CHECK-8: @_ZTV1FIlE = weak_odr constant +// CHECK-8: @_ZTV1FIlE = weak_odr unnamed_addr constant // CHECK-8: @_ZTS1FIlE = weak_odr constant // CHECK-8: @_ZTI1FIlE = weak_odr constant // F is an explicit template instantiation declaration without a // key function, so its vtable should have external linkage. -// CHECK-9: @_ZTV1FIiE = external constant +// CHECK-9: @_ZTV1FIiE = external unnamed_addr constant // E is an explicit template instantiation declaration. It has a // key function that is not instantiated, so we should only reference // its vtable, not define it. -// CHECK-10: @_ZTV1EIiE = external constant +// CHECK-10: @_ZTV1EIiE = external unnamed_addr constant // The anonymous struct for e has no linkage, so the vtable should have // internal linkage. -// CHECK-11: @"_ZTV3$_0" = internal constant +// CHECK-11: @"_ZTV3$_0" = internal unnamed_addr constant // CHECK-11: @"_ZTS3$_0" = internal constant // CHECK-11: @"_ZTI3$_0" = internal constant // The A vtable should have internal linkage since it is inside an anonymous // namespace. -// CHECK-12: @_ZTVN12_GLOBAL__N_11AE = internal constant +// CHECK-12: @_ZTVN12_GLOBAL__N_11AE = internal unnamed_addr constant // CHECK-12: @_ZTSN12_GLOBAL__N_11AE = internal constant // CHECK-12: @_ZTIN12_GLOBAL__N_11AE = internal constant // F is an explicit specialization without a key function, so // its vtable should have weak_odr linkage. -// CHECK-13: @_ZTV1FIcE = weak_odr constant +// CHECK-13: @_ZTV1FIcE = weak_odr unnamed_addr 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 +// CHECK-G: @_ZTV1GIiE = weak_odr unnamed_addr constant template class G { public: @@ -202,7 +202,7 @@ void G_f0() { new G(); } // H has a key function without a body but it's a template instantiation // so its VTable must be emmitted. -// CHECK-H: @_ZTV1HIiE = weak_odr constant +// CHECK-H: @_ZTV1HIiE = weak_odr unnamed_addr constant template class H { public: