Skip to content

[cxx-interop] Simplify finding copy/move ctors in IRGen #77855

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
Dec 2, 2024
Merged
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
35 changes: 14 additions & 21 deletions lib/IRGen/GenStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,36 +563,29 @@ namespace {
const clang::RecordDecl *ClangDecl;

const clang::CXXConstructorDecl *findCopyConstructor() const {
const clang::CXXRecordDecl *cxxRecordDecl =
dyn_cast<clang::CXXRecordDecl>(ClangDecl);
const auto *cxxRecordDecl = dyn_cast<clang::CXXRecordDecl>(ClangDecl);
if (!cxxRecordDecl)
return nullptr;
for (auto method : cxxRecordDecl->methods()) {
if (auto ctor = dyn_cast<clang::CXXConstructorDecl>(method)) {
if (ctor->isCopyConstructor() &&
ctor->getAccess() == clang::AS_public &&
// rdar://106964356
// ctor->doesThisDeclarationHaveABody() &&
!ctor->isDeleted())
return ctor;
}
for (auto ctor : cxxRecordDecl->ctors()) {
if (ctor->isCopyConstructor() &&
ctor->getAccess() == clang::AS_public &&
// rdar://106964356
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add naked radar links to the main source code like this. First and foremost, you should describe the issue that you're working around instead of just adding a link. Second, this is an open-source project, so you should really link to an open source GitHub issue which will be readable by non-Apple employees.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. This one was here before my change. I'll try to replace it with the summary of what the rdar is about in a followup PR.

// ctor->doesThisDeclarationHaveABody() &&
!ctor->isDeleted())
return ctor;
}
return nullptr;
}

const clang::CXXConstructorDecl *findMoveConstructor() const {
const clang::CXXRecordDecl *cxxRecordDecl =
dyn_cast<clang::CXXRecordDecl>(ClangDecl);
const auto *cxxRecordDecl = dyn_cast<clang::CXXRecordDecl>(ClangDecl);
if (!cxxRecordDecl)
return nullptr;
for (auto method : cxxRecordDecl->methods()) {
if (auto ctor = dyn_cast<clang::CXXConstructorDecl>(method)) {
if (ctor->isMoveConstructor() &&
ctor->getAccess() == clang::AS_public &&
ctor->doesThisDeclarationHaveABody() &&
!ctor->isDeleted())
return ctor;
}
for (auto ctor : cxxRecordDecl->ctors()) {
if (ctor->isMoveConstructor() &&
ctor->getAccess() == clang::AS_public &&
ctor->doesThisDeclarationHaveABody() && !ctor->isDeleted())
return ctor;
}
return nullptr;
}
Expand Down