浏览代码

PR10120: Make CodeGenModule::getVTableLinkage use NamedDecl::getLinkage to determine whether the vtable should be externally visible, instead of a rough approximation of it which messes up with templates.

While I'm here, zap the other user of isInAnonymousNamespace outside of Decl.cpp.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132861 91177308-0d34-0410-b5e6-96231b3b80d8
Eli Friedman 14 年之前
父节点
当前提交
cb5d2d0647
共有 3 个文件被更改,包括 11 次插入3 次删除
  1. 2 2
      lib/AST/RecordLayoutBuilder.cpp
  2. 1 1
      lib/CodeGen/CodeGenModule.cpp
  3. 8 0
      test/CodeGenCXX/internal-linkage.cpp

+ 2 - 2
lib/AST/RecordLayoutBuilder.cpp

@@ -1757,10 +1757,10 @@ RecordLayoutBuilder::ComputeKeyFunction(const CXXRecordDecl *RD) {
   if (!RD->isPolymorphic())
     return 0;
 
-  // A class inside an anonymous namespace doesn't have a key function.  (Or
+  // A class that is not externally visible doesn't have a key function. (Or
   // at least, there's no point to assigning a key function to such a class;
   // this doesn't affect the ABI.)
-  if (RD->isInAnonymousNamespace())
+  if (RD->getLinkage() != ExternalLinkage)
     return 0;
 
   // Template instantiations don't have key functions,see Itanium C++ ABI 5.2.6.

+ 1 - 1
lib/CodeGen/CodeGenModule.cpp

@@ -1125,7 +1125,7 @@ void CodeGenModule::EmitVTable(CXXRecordDecl *Class, bool DefinitionRequired) {
 
 llvm::GlobalVariable::LinkageTypes 
 CodeGenModule::getVTableLinkage(const CXXRecordDecl *RD) {
-  if (RD->isInAnonymousNamespace() || !RD->hasLinkage())
+  if (RD->getLinkage() != ExternalLinkage)
     return llvm::GlobalVariable::InternalLinkage;
 
   if (const CXXMethodDecl *KeyFunction

+ 8 - 0
test/CodeGenCXX/internal-linkage.cpp

@@ -54,3 +54,11 @@ char const * *test4()
     // CHECK: @extern_nonconst_xyzzy = global
     return &extern_nonconst_xyzzy;
 }
+
+// PR10120
+template <typename T> class klass {
+    virtual void f();
+};
+namespace { struct S; }
+void foo () { klass<S> x; }
+// CHECK: @_ZTV5klassIN12_GLOBAL__N_11SEE = internal unnamed_addr constant