Skip to content

🍒[cxx-interop] Always instantiate the default destructor #74934

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/IRGen/GenClangDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ void IRGenModule::emitClangDecl(const clang::Decl *decl) {
// Unfortunately, implicitly defined CXXDestructorDecls don't have a real
// body, so we need to traverse these manually.
if (auto *dtor = dyn_cast<clang::CXXDestructorDecl>(next)) {
if (dtor->isImplicit() && dtor->isDefaulted() && !dtor->isDeleted() &&
!dtor->doesThisDeclarationHaveABody())
clangSema.DefineImplicitDestructor(dtor->getLocation(), dtor);

if (dtor->isImplicit() || dtor->hasBody()) {
auto cxxRecord = dtor->getParent();

Expand Down
12 changes: 12 additions & 0 deletions test/Interop/Cxx/class/Inputs/destructors.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ struct HasNonTrivialImplicitDestructor {
HasUserProvidedDestructor member;
};

template <typename T>
struct TemplatedHasVirtualDestructor {
T value;
virtual ~TemplatedHasVirtualDestructor() {}
};

template <typename T>
struct DerivedTemplatedHasVirtualDestructor : TemplatedHasVirtualDestructor<T> {
};

using DerivedTemplatedHasVirtualDestructorChar = DerivedTemplatedHasVirtualDestructor<char>;

#endif // TEST_INTEROP_CXX_CLASS_INPUTS_DESTRUCTORS_H
9 changes: 9 additions & 0 deletions test/Interop/Cxx/class/destructors-templated-irgen.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %target-swiftxx-frontend -emit-ir -I %S/Inputs -validate-tbd-against-ir=none %s | %FileCheck %s

import Destructors

let _ = DerivedTemplatedHasVirtualDestructorChar()

// CHECK: define {{.*}} @{{_ZN36DerivedTemplatedHasVirtualDestructorIcED2Ev|"\?\?1\?\$DerivedTemplatedHasVirtualDestructor@D@@UEAA@XZ"}}
// CHECK: entry:
// CHECK: call {{.*}} @{{_ZN29TemplatedHasVirtualDestructorIcED2Ev|"\?\?1\?\$TemplatedHasVirtualDestructor@D@@UEAA@XZ"}}