Skip to content

[interop] do not assume we need to IRGen destructors of fields inside… #64623

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 1 commit into from
Mar 26, 2023
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
22 changes: 12 additions & 10 deletions lib/IRGen/GenClangDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,20 @@ 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)) {
auto cxxRecord = dtor->getParent();
if (dtor->isImplicit() || dtor->hasBody()) {
auto cxxRecord = dtor->getParent();

for (auto field : cxxRecord->fields()) {
if (auto fieldCxxRecord = field->getType()->getAsCXXRecordDecl())
if (auto *fieldDtor = fieldCxxRecord->getDestructor())
callback(fieldDtor);
}
for (auto field : cxxRecord->fields()) {
if (auto fieldCxxRecord = field->getType()->getAsCXXRecordDecl())
if (auto *fieldDtor = fieldCxxRecord->getDestructor())
callback(fieldDtor);
}

for (auto base : cxxRecord->bases()) {
if (auto baseCxxRecord = base.getType()->getAsCXXRecordDecl())
if (auto *baseDtor = baseCxxRecord->getDestructor())
callback(baseDtor);
for (auto base : cxxRecord->bases()) {
if (auto baseCxxRecord = base.getType()->getAsCXXRecordDecl())
if (auto *baseDtor = baseCxxRecord->getDestructor())
callback(baseDtor);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,29 @@ private:
BaseClass *pointer;
};

class ForwardClassDecl;

template<class T>
class ContainerWithForward {
public:
inline ~ContainerWithForward() {
if (sizeof(T) > 0)
referencedSymbol();
}
};

class ClassWithOutOfLineDestructor {
public:
~ClassWithOutOfLineDestructor();

ContainerWithForward<ForwardClassDecl> field;
};

ClassWithOutOfLineDestructor *getClassWithOutOfLineDestructorValue();

inline void testMethodDestructorFwdDecl() {
delete getClassWithOutOfLineDestructorValue();
}

//--- test.swift

Expand All @@ -41,6 +64,7 @@ import DestroyedUsingDelete
public func test() {
let i = Container()
i.method()
testMethodDestructorFwdDecl()
}

// Make sure we reach destructor accessible from `delete` statement.
Expand Down