summaryrefslogtreecommitdiffstats
path: root/lib/CodeGen/MicrosoftCXXABI.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-02-10 17:40:47 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-02-10 17:40:47 +0000
commitf813c829dd9e628b456e9df9826bba69f7224a92 (patch)
tree28c2f40f6c164563b24eb33fa1379e9ab6c2f731 /lib/CodeGen/MicrosoftCXXABI.cpp
parent222af3db18686a08f455b6a5132de5a98d0273f4 (diff)
[MS ABI] Never reference dllimport'd vtables
Referencing a dllimported vtable is impossible in a constexpr constructor. It would be friendlier to C++ programmers if we synthesized a copy of the vftable which referenced imported virtual functions. This would let us initialize the object in a way which preserves both the intent to import functionality from another DLL while also making constexpr work. Differential Revision: http://reviews.llvm.org/D17061 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260388 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/MicrosoftCXXABI.cpp')
-rw-r--r--lib/CodeGen/MicrosoftCXXABI.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/CodeGen/MicrosoftCXXABI.cpp b/lib/CodeGen/MicrosoftCXXABI.cpp
index 0664381b44..f47b120a90 100644
--- a/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -1673,7 +1673,16 @@ llvm::GlobalVariable *MicrosoftCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
SmallString<256> VFTableName;
mangleVFTableName(getMangleContext(), RD, VFPtr, VFTableName);
- llvm::GlobalValue::LinkageTypes VFTableLinkage = CGM.getVTableLinkage(RD);
+ // Classes marked __declspec(dllimport) need vftables generated on the
+ // import-side in order to support features like constexpr. No other
+ // translation unit relies on the emission of the local vftable, translation
+ // units are expected to generate them as needed.
+ //
+ // Because of this unique behavior, we maintain this logic here instead of
+ // getVTableLinkage.
+ llvm::GlobalValue::LinkageTypes VFTableLinkage =
+ RD->hasAttr<DLLImportAttr>() ? llvm::GlobalValue::LinkOnceODRLinkage
+ : CGM.getVTableLinkage(RD);
bool VFTableComesFromAnotherTU =
llvm::GlobalValue::isAvailableExternallyLinkage(VFTableLinkage) ||
llvm::GlobalValue::isExternalLinkage(VFTableLinkage);
@@ -1746,9 +1755,7 @@ llvm::GlobalVariable *MicrosoftCXXABI::getAddrOfVTable(const CXXRecordDecl *RD,
if (C)
VTable->setComdat(C);
- if (RD->hasAttr<DLLImportAttr>())
- VFTable->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);
- else if (RD->hasAttr<DLLExportAttr>())
+ if (RD->hasAttr<DLLExportAttr>())
VFTable->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass);
VFTablesMap[ID] = VFTable;