[6.2][cxx-interop] Fix runtime crash passing FRTs as const FRT* #81096
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.
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