r244266 - [ItaniumCXXABI] Don't import RTTI data for classes with key functions
David Majnemer via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 6 13:56:55 PDT 2015
Author: majnemer
Date: Thu Aug 6 15:56:55 2015
New Revision: 244266
URL: http://llvm.org/viewvc/llvm-project?rev=244266&view=rev
Log:
[ItaniumCXXABI] Don't import RTTI data for classes with key functions
MinGW has some pretty strange behvaior around RTTI and
dllimport/dllexport:
- RTTI data is never imported
- RTTI data is only exported if the class has no key function.
Modified:
cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp
Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=244266&r1=244265&r2=244266&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Thu Aug 6 15:56:55 2015
@@ -2450,10 +2450,13 @@ static bool ShouldUseExternalRTTIDescrip
// FIXME: this may need to be reconsidered if the key function
// changes.
+ // N.B. We must always emit the RTTI data ourselves if there exists a key
+ // function.
+ bool IsDLLImport = RD->hasAttr<DLLImportAttr>();
if (CGM.getVTables().isVTableExternal(RD))
- return true;
+ return IsDLLImport ? false : true;
- if (RD->hasAttr<DLLImportAttr>())
+ if (IsDLLImport)
return true;
}
@@ -2683,8 +2686,15 @@ static llvm::GlobalVariable::LinkageType
const CXXRecordDecl *RD = cast<CXXRecordDecl>(Record->getDecl());
if (RD->hasAttr<WeakAttr>())
return llvm::GlobalValue::WeakODRLinkage;
- if (RD->isDynamicClass())
- return CGM.getVTableLinkage(RD);
+ if (RD->isDynamicClass()) {
+ llvm::GlobalValue::LinkageTypes LT = CGM.getVTableLinkage(RD);
+ // MinGW won't export the RTTI information when there is a key function.
+ // Make sure we emit our own copy instead of attempting to dllimport it.
+ if (RD->hasAttr<DLLImportAttr>() &&
+ llvm::GlobalValue::isAvailableExternallyLinkage(LT))
+ LT = llvm::GlobalValue::LinkOnceODRLinkage;
+ return LT;
+ }
}
return llvm::GlobalValue::LinkOnceODRLinkage;
Modified: cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp?rev=244266&r1=244265&r2=244266&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dllimport-rtti.cpp Thu Aug 6 15:56:55 2015
@@ -15,3 +15,10 @@ struct __declspec(dllimport) S {
struct U : S {
} u;
+
+struct __declspec(dllimport) V {
+ virtual void f();
+} v;
+// GNU-DAG: @_ZTV1V = available_externally dllimport
+// GNU-DAG: @_ZTS1V = linkonce_odr
+// GNU-DAG: @_ZTI1V = linkonce_odr
More information about the cfe-commits
mailing list