Skip to content

[6.2][cxx-interop] Fix runtime crash passing FRTs as const FRT* #81096

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
Apr 25, 2025

Conversation

Xazax-hun
Copy link
Contributor

Explanation: There was an inconsistency between non-const and const FRT pointers. The former used Direct_Unowned the latter used Indirect calling convention. We want to use Direct_Unowned for both cases. The crash was the result of a calling convention mismatch between the SILFunctionType of a Swift closure and the SILFunctionType of the C++ function's formal parameter that is taking a function pointer. The compiler tried to insert a conversion between the two function types that does not exist and caused an assertion in debug compilers and miscompilation in production compilers.
Issue: rdar://149398905
Risk: Low, the fix is targeted and we change to a well-tested behavior with non-const FRT pointers.
Testing: Regression test added.
Original PR: #81070
Reviewer: @j-hui

Explanation: There was an inconsistency between non-const and const FRT
pointers. The former used Direct_Unowned the latter used Indirect
calling convention. We want to use Direct_Unowned for both cases. The
crash was the result of a calling convention mismatch between the
SILFunctionType of a Swift closure and the SILFunctionType of the C++
function's formal parameter that is taking a function pointer. The
compiler tried to insert a conversion between the two function types
that does not exist and caused an assertion in debug compilers and
miscompilation in production compilers.
Issue: rdar://149398905
Risk: Low, the fix is targeted and we change to a well-tested behavior
with non-const FRT pointers.
Testing: Regression test added.
Original PR: #81070
Reviewer: @j-hui
@Xazax-hun Xazax-hun added c++ interop Feature: Interoperability with C++ 🍒 release cherry pick Flag: Release branch cherry picks swift 6.2 labels Apr 25, 2025
@Xazax-hun Xazax-hun requested a review from j-hui April 25, 2025 10:05
@Xazax-hun Xazax-hun requested a review from a team as a code owner April 25, 2025 10:05
@Xazax-hun
Copy link
Contributor Author

@swift-ci please test

@Xazax-hun
Copy link
Contributor Author

@swift-ci please test macOS

@Xazax-hun Xazax-hun merged commit 8783ff9 into release/6.2 Apr 25, 2025
5 checks passed
@Xazax-hun Xazax-hun deleted the gaborh/frt-const-ptr-crash-on-6.2 branch April 25, 2025 21:03
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++ 🍒 release cherry pick Flag: Release branch cherry picks swift 6.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants