Skip to content

[6.2][cxx-interop] Work around crash in codegen when initializing C++ span #81047

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 24, 2025

Conversation

Xazax-hun
Copy link
Contributor

@Xazax-hun Xazax-hun commented Apr 23, 2025

Explanation: C++ templates are imported as Swift generics. Unfortunately, the codegen for some of the instantiations will crash codegen due to a confusion in how Swift pointer types are mapped back to their native counterparts. As a result, when a user is passing an UnsafePointer? to a C++ span constructor we got a crash. The user should never need the generic version of the initializer as we already have an initializer taking an UnsafePointer in the C++ overlay. This PR avoids importing the templated span constructors to work around this issue.
Issue: rdar://148961349
Risk: Low, the fix is very targeted.
Testing: Regression test added.
Original PR: #81030
Reviewer: @j-hui

… span

Explanation: C++ templates are imported as Swift generics.
Unfortunately, the codegen for some of the instantiations will crash
codegen due to a confusion in how Swift pointer types are mapped back to their
native counterparts. As a result, when a user is passing an
UnsafePointer<Element>? to a C++ span constructor we got a crash. The
user should never need the generic version of the initializer as we
already have an initializer taking an UnsafePointer<Element> in the C++
overlay. This PR avoids importing the templated span constructors to
work around this issue.
Issue: rdar://148961349
Risk: Low, the fix is very targeted.
Testing: Regression test added.
Original PR: #81030
Reviewer: @j-hui
@Xazax-hun Xazax-hun added the c++ interop Feature: Interoperability with C++ label Apr 23, 2025
@Xazax-hun Xazax-hun requested a review from j-hui April 23, 2025 20:52
@Xazax-hun Xazax-hun requested a review from a team as a code owner April 23, 2025 20:52
@Xazax-hun
Copy link
Contributor Author

@swift-ci please test

@Xazax-hun Xazax-hun changed the title [6.2][cxx-interop] Work around crash in codegen when initializing C++… [6.2][cxx-interop] Work around crash in codegen when initializing C++ span Apr 23, 2025
@Xazax-hun Xazax-hun merged commit 1c92940 into release/6.2 Apr 24, 2025
5 checks passed
@Xazax-hun Xazax-hun deleted the gaborh/span-ctor-crash-6.2 branch April 24, 2025 06: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.

3 participants