[cfe-commits] r92857 - in /cfe/trunk/lib/CodeGen: CGRTTI.cpp CodeGenModule.cpp CodeGenModule.h
Douglas Gregor
dgregor at apple.com
Wed Jan 6 14:00:56 PST 2010
Author: dgregor
Date: Wed Jan 6 16:00:56 2010
New Revision: 92857
URL: http://llvm.org/viewvc/llvm-project?rev=92857&view=rev
Log:
Fix linkage for RTTI names by re-using the logic for computing the
linkage of vtables. Before this, we were emitting RTTI names for
template instantiations with strong external linkage rather than with
weak ODR linkage.
Modified:
cfe/trunk/lib/CodeGen/CGRTTI.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
Modified: cfe/trunk/lib/CodeGen/CGRTTI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRTTI.cpp?rev=92857&r1=92856&r2=92857&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRTTI.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRTTI.cpp Wed Jan 6 16:00:56 2010
@@ -360,27 +360,12 @@
// If we're in an anonymous namespace, then we always want internal linkage.
if (RD->isInAnonymousNamespace() || !RD->hasLinkage())
return llvm::GlobalVariable::InternalLinkage;
-
+
+ // If this class does not have a vtable, we want weak linkage.
if (!RD->isDynamicClass())
return llvm::GlobalValue::WeakODRLinkage;
- // Get the key function.
- const CXXMethodDecl *KeyFunction = RD->getASTContext().getKeyFunction(RD);
- if (!KeyFunction) {
- // There is no key function, the RTTI descriptor is emitted with weak_odr
- // linkage.
- return llvm::GlobalValue::WeakODRLinkage;
- }
-
- // If the key function is defined, but inlined, then the RTTI descriptor is
- // emitted with weak_odr linkage.
- const FunctionDecl* KeyFunctionDefinition;
- if (KeyFunction->getBody(KeyFunctionDefinition) &&
- KeyFunctionDefinition->isInlined())
- return llvm::GlobalValue::WeakODRLinkage;
-
- // Otherwise, the RTTI descriptor is emitted with external linkage.
- return llvm::GlobalValue::ExternalLinkage;
+ return CodeGenModule::getVtableLinkage(RD);
}
case Type::Vector:
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=92857&r1=92856&r2=92857&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Jan 6 16:00:56 2010
@@ -889,18 +889,17 @@
llvm::GlobalVariable::LinkageTypes
CodeGenModule::getVtableLinkage(const CXXRecordDecl *RD) {
- // Get the key function.
- const CXXMethodDecl *KeyFunction = getContext().getKeyFunction(RD);
-
- if (KeyFunction) {
+ if (RD->isInAnonymousNamespace() || !RD->hasLinkage())
+ return llvm::GlobalVariable::InternalLinkage;
+
+ if (const CXXMethodDecl *KeyFunction
+ = RD->getASTContext().getKeyFunction(RD)) {
+ // If this class has a key function, use that to determine the linkage of
+ // the vtable.
const FunctionDecl *Def = 0;
if (KeyFunction->getBody(Def))
KeyFunction = cast<CXXMethodDecl>(Def);
- }
-
- if (RD->isInAnonymousNamespace() || !RD->hasLinkage())
- return llvm::GlobalVariable::InternalLinkage;
- else if (KeyFunction) {
+
switch (KeyFunction->getTemplateSpecializationKind()) {
case TSK_Undeclared:
case TSK_ExplicitSpecialization:
@@ -919,22 +918,20 @@
// return llvm::GlobalVariable::AvailableExternallyLinkage;
return llvm::GlobalVariable::WeakODRLinkage;
}
- } else if (KeyFunction) {
+ }
+
+ switch (RD->getTemplateSpecializationKind()) {
+ case TSK_Undeclared:
+ case TSK_ExplicitSpecialization:
+ case TSK_ImplicitInstantiation:
+ case TSK_ExplicitInstantiationDefinition:
+ return llvm::GlobalVariable::WeakODRLinkage;
+
+ case TSK_ExplicitInstantiationDeclaration:
+ // FIXME: Use available_externally linkage. However, this currently
+ // breaks LLVM's build due to undefined symbols.
+ // return llvm::GlobalVariable::AvailableExternallyLinkage;
return llvm::GlobalVariable::WeakODRLinkage;
- } else {
- switch (RD->getTemplateSpecializationKind()) {
- case TSK_Undeclared:
- case TSK_ExplicitSpecialization:
- case TSK_ImplicitInstantiation:
- case TSK_ExplicitInstantiationDefinition:
- return llvm::GlobalVariable::WeakODRLinkage;
-
- case TSK_ExplicitInstantiationDeclaration:
- // FIXME: Use available_externally linkage. However, this currently
- // breaks LLVM's build due to undefined symbols.
- // return llvm::GlobalVariable::AvailableExternallyLinkage;
- return llvm::GlobalVariable::WeakODRLinkage;
- }
}
// Silence GCC warning.
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=92857&r1=92856&r2=92857&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Wed Jan 6 16:00:56 2010
@@ -409,7 +409,8 @@
/// getVtableLinkage - Return the appropriate linkage for the vtable, VTT,
/// and type information of the given class.
- llvm::GlobalVariable::LinkageTypes getVtableLinkage(const CXXRecordDecl *RD);
+ static llvm::GlobalVariable::LinkageTypes
+ getVtableLinkage(const CXXRecordDecl *RD);
private:
/// UniqueMangledName - Unique a name by (if necessary) inserting it into the
More information about the cfe-commits
mailing list