[cxx-interop] Itanium ABI C++ records should have address-only layout when they can't be passed in registers#66694
Merged
hyp merged 4 commits intoswiftlang:release/5.9from Jun 16, 2023
Merged
Conversation
…an't be passed in registers This ensures that a C++ record with only ObjC ARC pointers with trivial other members is passed by value in SIL Fixes swiftlang#61929 (cherry picked from commit decd21f)
…ble in Swift (cherry picked from commit 2c4188b)
…t failure on macOS (cherry picked from commit 988f373)
(cherry picked from commit 7abd265)
Contributor
Author
|
@swift-ci please test |
Contributor
Author
|
@swift-ci please test source compatibility |
DougGregor
approved these changes
Jun 16, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This ensures that a C++ record with only ObjC ARC pointers with trivial other members is passed by value in SIL.
Fixes #61929
Additionally, mark C++ classes with trivial_abi attribute as unavailable in Swift.
Non-trivial C++ records become AddressOnly Swift structures, as that's the only way to guarantee the invocation of their copy and/or destroy operations from Swift. AddressOnly implies indirect parameter passing as well. However, under Itanium ABI, some C++ records that have only ARC pointers can be passed directly even though they're non-trivial types. This causes a runtime crash as we think such C++ records are passed indirectly instead from Swift.
This change modifies the way we decide which records become AddressOnly Swift structs on Itanium ABI, by using Clang's own mechanism that determines if the record can be passed in registers or not. This largely aligns the semantics of C++'s indirect + non-trivial copy/destroy with Swift's AddressOnly semantics, except for C++ records annotated with
trivial_abi. Such types are now marked as unavailable in Swift instead, as they can't be supported yet in the current implementation.On Windows for the MSVC target the situation is more complicated, and this patch leaves the current behavior instead. The problem is that the MSVC ABI allows non-trivially destroyed but trivially copyable C++ records to be passed in registers. This can't be supported without AddressOnly in Swift, as we wouldn't be able to destroy such C++ record correctly. Thus, for now, preserve the existing behavior. A follow-up future fix will need to teach Swift's code generator how to pass AddressOnly C++ records directly to fix both the MSVC ABI and to support
trivial_abifor Itanium as well.trivial_abirecords though. We are not aware of any adopters usingtrivial_abirecords yet, so that shouldn't be a concern at the moment.