From 470fb73d4e09e1dfe62cb545d7fe0e567ac6e8d6 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Fri, 11 Dec 2009 20:48:18 +0000 Subject: [PATCH] Fix linkage of type info and vtable for classes without linkage. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91152 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGRTTI.cpp | 4 ++-- lib/CodeGen/CGVtable.cpp | 2 +- test/CodeGenCXX/vtable-linkage.cpp | 8 ++++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/CodeGen/CGRTTI.cpp b/lib/CodeGen/CGRTTI.cpp index a574703935..a15ba4f215 100644 --- a/lib/CodeGen/CGRTTI.cpp +++ b/lib/CodeGen/CGRTTI.cpp @@ -230,7 +230,7 @@ public: return llvm::ConstantExpr::getBitCast(GV, Int8PtrTy); // If we're in an anonymous namespace, then we always want internal linkage. - if (RD->isInAnonymousNamespace()) + if (RD->isInAnonymousNamespace() || !RD->hasLinkage()) Linkage = llvm::GlobalVariable::InternalLinkage; bool Hidden = CGM.getDeclVisibilityMode(RD) == LangOptions::Hidden; @@ -295,7 +295,7 @@ public: return DecideExtern(PT->getPointeeType()); if (const RecordType *RT = Ty->getAs()) if (const CXXRecordDecl *RD = dyn_cast(RT->getDecl())) - return !RD->isInAnonymousNamespace(); + return !RD->isInAnonymousNamespace() && RD->hasLinkage(); return true; } diff --git a/lib/CodeGen/CGVtable.cpp b/lib/CodeGen/CGVtable.cpp index 752f69c7c2..868a341440 100644 --- a/lib/CodeGen/CGVtable.cpp +++ b/lib/CodeGen/CGVtable.cpp @@ -1458,7 +1458,7 @@ void CGVtableInfo::MaybeEmitVtable(GlobalDecl GD) { } llvm::GlobalVariable::LinkageTypes Linkage; - if (RD->isInAnonymousNamespace()) + if (RD->isInAnonymousNamespace() || !RD->hasLinkage()) Linkage = llvm::GlobalVariable::InternalLinkage; else if (KeyFunction && !MD->isInlined()) Linkage = llvm::GlobalVariable::ExternalLinkage; diff --git a/test/CodeGenCXX/vtable-linkage.cpp b/test/CodeGenCXX/vtable-linkage.cpp index 5bc509b65e..f2d914feed 100644 --- a/test/CodeGenCXX/vtable-linkage.cpp +++ b/test/CodeGenCXX/vtable-linkage.cpp @@ -28,6 +28,8 @@ struct D { void D::f() { } +static struct : D { } e; + // B has a key function that is not defined in this translation unit so its vtable // has external linkage. // CHECK: @_ZTV1B = external constant @@ -43,6 +45,12 @@ void D::f() { } // CHECK: @_ZTI1D = constant // CHECK: @_ZTV1D = constant +// The anonymous struct for e has no linkage, so the vtable should have +// internal linkage. +// CHECK: @"_ZTS3$_0" = internal constant +// CHECK: @"_ZTI3$_0" = internal constant +// CHECK: @"_ZTV3$_0" = internal constant + // The A vtable should have internal linkage since it is inside an anonymous // namespace. // CHECK: @_ZTSN12_GLOBAL__N_11AE = internal constant