Index: lib/CodeGen/ItaniumCXXABI.cpp =================================================================== --- lib/CodeGen/ItaniumCXXABI.cpp +++ lib/CodeGen/ItaniumCXXABI.cpp @@ -284,6 +284,14 @@ // linkage together with vtables when needed. if (ForVTable && !Thunk->hasLocalLinkage()) Thunk->setLinkage(llvm::GlobalValue::AvailableExternallyLinkage); + + // Propagate dllexport storage, to enable the linker to generate import + // thunks as necessary (e.g. when a parent class has a key function and a + // child class doesn't, and the construction vtable for the parent in the + // child needs to reference the parent's thunks). + const CXXMethodDecl *MD = cast(GD.getDecl()); + if (MD->hasAttr()) + Thunk->setDLLStorageClass(llvm::GlobalValue::DLLExportStorageClass); } llvm::Value *performThisAdjustment(CodeGenFunction &CGF, Address This, Index: test/CodeGenCXX/dllexport-vtable-thunks.cpp =================================================================== --- /dev/null +++ test/CodeGenCXX/dllexport-vtable-thunks.cpp @@ -0,0 +1,23 @@ +// RUN: %clang_cc1 -triple x86_64-windows-gnu -fdeclspec -emit-llvm -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple x86_64-windows-itanium -fdeclspec -emit-llvm -o - %s | FileCheck %s + +struct __declspec(dllexport) A { + virtual void m(); +}; +struct __declspec(dllexport) B { + virtual void m(); +}; +struct __declspec(dllexport) C : A, B { + virtual void m(); +}; +void C::m() {} +// CHECK: define dllexport void @_ZThn8_N1C1mEv + +struct Base { + virtual void m(); +}; +struct __declspec(dllexport) Derived : virtual Base { + virtual void m(); +}; +void Derived::m() {} +// CHECK: define dllexport void @_ZTv0_n24_N7Derived1mEv