Skip to content

Commit 705a6ae

Browse files
committed
[MS] Emit exported complete/vbase destructors
Summary: Fixes PR44205 I checked, and deleting destructors are not affected. Reviewers: hans Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70931
1 parent ad871e4 commit 705a6ae

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

clang/lib/CodeGen/MicrosoftCXXABI.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,13 @@ void MicrosoftCXXABI::EmitCXXDestructors(const CXXDestructorDecl *D) {
13431343
// The TU defining a dtor is only guaranteed to emit a base destructor. All
13441344
// other destructor variants are delegating thunks.
13451345
CGM.EmitGlobal(GlobalDecl(D, Dtor_Base));
1346+
1347+
// If the class is dllexported, emit the complete (vbase) destructor wherever
1348+
// the base dtor is emitted.
1349+
// FIXME: To match MSVC, this should only be done when the class is exported
1350+
// with -fdllexport-inlines enabled.
1351+
if (D->getParent()->getNumVBases() > 0 && D->hasAttr<DLLExportAttr>())
1352+
CGM.EmitGlobal(GlobalDecl(D, Dtor_Complete));
13461353
}
13471354

13481355
CharUnits

clang/test/CodeGenCXX/dllexport-dtor-thunks.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
// RUN: %clang_cc1 -mconstructor-aliases -fms-extensions %s -emit-llvm -o - -triple x86_64-windows-msvc | FileCheck %s
22

3+
namespace test1 {
4+
struct A { ~A(); };
5+
struct __declspec(dllexport) B : virtual A { };
6+
// CHECK: define weak_odr dso_local dllexport void @"??1B@test1@@QEAA@XZ"
7+
// CHECK: define weak_odr dso_local dllexport void @"??_DB@test1@@QEAAXXZ"
8+
}
9+
310
struct __declspec(dllexport) A { virtual ~A(); };
411
struct __declspec(dllexport) B { virtual ~B(); };
512
struct __declspec(dllexport) C : A, B { virtual ~C(); };

clang/test/CodeGenCXX/dllimport-dtor-thunks.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ struct __declspec(dllimport) ImportOverrideVDtor : public BaseClass {
1919
virtual ~ImportOverrideVDtor() {}
2020
};
2121

22-
// Virtually inherits from a non-dllimport base class. This time we need to call
23-
// the complete destructor and emit it inline. It's not exported from the DLL,
24-
// and it must be emitted.
22+
// Virtually inherits from a non-dllimport base class. In this case, we can
23+
// expect the DLL to provide a definition of the complete dtor. See
24+
// dllexport-dtor-thunks.cpp.
2525
struct __declspec(dllimport) ImportVBaseOverrideVDtor
2626
: public virtual BaseClass {
2727
virtual ~ImportVBaseOverrideVDtor() {}

0 commit comments

Comments
 (0)