Skip to content

Commit f4949bd

Browse files
committed
fix
1 parent cd1ca50 commit f4949bd

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

lib/IRGen/GenClangDecl.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void IRGenModule::emitClangDecl(const clang::Decl *decl) {
287287
if (auto *destructor = record->getDestructor()) {
288288
// Ensure virtual destructors have the body defined, even if they're
289289
// not used directly, as they might be referenced by the emitted vtable.
290-
if (destructor->isVirtual())
290+
if (destructor->isVirtual() && !destructor->isDeleted())
291291
ensureImplicitCXXDestructorBodyIsDefined(destructor);
292292
}
293293
for (auto *method : record->methods()) {
@@ -342,12 +342,12 @@ void IRGenModule::finalizeClangCodeGen() {
342342

343343
void IRGenModule::ensureImplicitCXXDestructorBodyIsDefined(
344344
clang::CXXDestructorDecl *destructor) {
345-
if (!destructor->isUserProvided() &&
346-
!destructor->doesThisDeclarationHaveABody()) {
347-
assert(!destructor->isDeleted() &&
348-
"Swift cannot handle a type with no known destructor.");
349-
// Make sure we define the destructor so we have something to call.
350-
auto &sema = Context.getClangModuleLoader()->getClangSema();
351-
sema.DefineImplicitDestructor(clang::SourceLocation(), destructor);
352-
}
345+
if (destructor->isUserProvided() ||
346+
destructor->doesThisDeclarationHaveABody())
347+
return;
348+
assert(!destructor->isDeleted() &&
349+
"Swift cannot handle a type with no known destructor.");
350+
// Make sure we define the destructor so we have something to call.
351+
auto &sema = Context.getClangModuleLoader()->getClangSema();
352+
sema.DefineImplicitDestructor(clang::SourceLocation(), destructor);
353353
}

test/Interop/Cxx/class/virtual-destructor-vtable-ref-irgen.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: rm -rf %t
22
// RUN: split-file %s %t
33
// RUN: %target-swiftxx-frontend -emit-ir -I %t/Inputs -validate-tbd-against-ir=none %t/test.swift | %FileCheck %s
4+
// RUN: %target-swiftxx-frontend -verify -emit-ir -I %t/Inputs -validate-tbd-against-ir=none %t/test.swift -Xcc -DDELETED -o /dev/null
45

56
//--- Inputs/module.modulemap
67
module VtableDestructorRef {
@@ -12,6 +13,27 @@ module VtableDestructorRef {
1213

1314
namespace impl {
1415

16+
#ifdef DELETED
17+
18+
template<class T>
19+
class BaseClass
20+
{
21+
public:
22+
~BaseClass() = delete;
23+
};
24+
25+
template<class Fp, class T>
26+
class Func: public BaseClass<T>
27+
{
28+
Fp x;
29+
public:
30+
inline explicit Func(Fp x);
31+
Func(const Func &) = delete;
32+
~Func();
33+
};
34+
35+
#else
36+
1537
template<class T>
1638
class BaseClass
1739
{
@@ -28,6 +50,7 @@ public:
2850
inline explicit Func(Fp x) : x(x) {}
2951
};
3052

53+
#endif
3154

3255
template <class _Fp> class ValueFunc;
3356

@@ -103,4 +126,4 @@ public func test() {
103126
}
104127

105128
// Make sure we reach the virtual destructor of 'Func'.
106-
// CHECK: define linkonce_odr {{.*}} @{{_ZN4impl4FuncIZNK8MyFutureIiE12OnCompletionEPFvPvES3_EUlRK12MyFutureBaseE_FvS8_EED2Ev|\?\?1\?\$BaseClass@\$\$A6AXAEBVMyFutureBase@@@Z@impl@@UEAA@XZ}}
129+
// CHECK: define linkonce_odr {{.*}} @{{_ZN4impl4FuncIZNK8MyFutureIiE12OnCompletionEPFvPvES3_EUlRK12MyFutureBaseE_FvS8_EED2Ev|"\?\?1\?\$BaseClass@\$\$A6AXAEBVMyFutureBase@@@Z@impl@@UEAA@XZ"}}

0 commit comments

Comments
 (0)