Skip to content

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

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

Conversation

Xazax-hun
Copy link
Contributor

When initializing span with an UnsafePointer? we call into the generic initializer that we imported from the C++ templated constructor instead of the concrete initializer we have in the overlay that takes an UnsafePointer (non-optional). We cannot properly codegen for this generic initializer at the moment, so let's stop importing them since the user probably wanted to call the initializer from the overlay.

We should come back later and fix the root cause.

rdar://148961349

When initializing span with an UnsafePointer<Element>? we call into the
generic initializer that we imported from the C++ templated constructor
instead of the concrete initializer we have in the overlay that takes an
UnsafePointer<Element> (non-optional). We cannot properly codegen for
this generic initializer at the moment, so let's stop importing them
since the user probably wanted to call the initializer from the overlay.

We should come back later and fix the root cause.

rdar://148961349
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

@Xazax-hun Xazax-hun merged commit c2f560e into main Apr 23, 2025
3 checks passed
@Xazax-hun Xazax-hun deleted the gaborh/span-ctor-crash branch April 23, 2025 19:46
Xazax-hun added a commit that referenced this pull request Apr 23, 2025
… 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
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