Skip to content

[cxx-interop] Clone all of the attributes from base method correctly #75058

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
Jul 9, 2024

Conversation

egorzhdan
Copy link
Contributor

If a C++ struct Base declares a method with a Clang attribute that Swift is able to import, and struct Derived inherits from Base, the method should get cloned from Base to Derived with its attributes.

Previously we were only cloning one attribute at most due to a bug in cloneImportedAttributes. DeclAttributes is an intrusively linked list, and it was being made invalid while iterating over it: otherDecl->getAttrs().add(attrs) iterates over the list and calls otherDecl->add(eachElement), which invalidates the iterator after the first iteration.

If a C++ `struct Base` declares a method with a Clang attribute that Swift is able to import, and `struct Derived` inherits from `Base`, the method should get cloned from `Base` to `Derived` with its attributes.

Previously we were only cloning one attribute at most due to a bug in `cloneImportedAttributes`. DeclAttributes is an intrusively linked list, and it was being made invalid while iterating over it: `otherDecl->getAttrs().add(attrs)` iterates over the list and calls `otherDecl->add(eachElement)`, which invalidates the iterator after the first iteration.
@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Jul 8, 2024
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@Xazax-hun Xazax-hun left a comment

Choose a reason for hiding this comment

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

LGTM!

@egorzhdan
Copy link
Contributor Author

@swift-ci please test Windows

@egorzhdan egorzhdan merged commit 14f39be into main Jul 9, 2024
3 checks passed
@egorzhdan egorzhdan deleted the egorzhdan/attrs-clone branch July 9, 2024 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ interop Feature: Interoperability with C++
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants