[cfe-commits] r91152 - in /cfe/trunk: lib/CodeGen/CGRTTI.cpp lib/CodeGen/CGVtable.cpp test/CodeGenCXX/vtable-linkage.cpp

Eli Friedman eli.friedman at gmail.com
Fri Dec 11 12:48:19 PST 2009


Author: efriedma
Date: Fri Dec 11 14:48:18 2009
New Revision: 91152

URL: http://llvm.org/viewvc/llvm-project?rev=91152&view=rev
Log:
Fix linkage of type info and vtable for classes without linkage.


Modified:
    cfe/trunk/lib/CodeGen/CGRTTI.cpp
    cfe/trunk/lib/CodeGen/CGVtable.cpp
    cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp

Modified: cfe/trunk/lib/CodeGen/CGRTTI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRTTI.cpp?rev=91152&r1=91151&r2=91152&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGRTTI.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRTTI.cpp Fri Dec 11 14:48:18 2009
@@ -230,7 +230,7 @@
       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 @@
       return DecideExtern(PT->getPointeeType());
     if (const RecordType *RT = Ty->getAs<RecordType>())
       if (const CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(RT->getDecl()))
-        return !RD->isInAnonymousNamespace();
+        return !RD->isInAnonymousNamespace() && RD->hasLinkage();
     return true;
   }
 

Modified: cfe/trunk/lib/CodeGen/CGVtable.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGVtable.cpp?rev=91152&r1=91151&r2=91152&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGVtable.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGVtable.cpp Fri Dec 11 14:48:18 2009
@@ -1458,7 +1458,7 @@
   }
 
   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;

Modified: cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp?rev=91152&r1=91151&r2=91152&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/vtable-linkage.cpp Fri Dec 11 14:48:18 2009
@@ -28,6 +28,8 @@
 
 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 @@
 // 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





More information about the cfe-commits mailing list