Skip to content

🍒 [6.2] Fix interop private debug symbols 6.2 #80718

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

Conversation

j-hui
Copy link
Contributor

@j-hui j-hui commented Apr 10, 2025

Cherry-pick of #80515, #80485

Explanation: The patch from #80485 fixes an assertion failure/compiler crash that is hit when the compiler tries to generate debug info for a private type decl imported from Clang. The assertion failure typically happens when we deliberately import private nested types (e.g., with the ImportNonPublicCxxMembers flag), but has been reported to occur in at least one adopter project that isn't using this feature flag.

The assertion failure is here, and is reached when one calls getFilePrivateScope() with a Clang decl. When it is compiled out in a no-assertions build, the compiler simply segfaults.

The getFilePrivateScope() function is normally necessary to disambiguate the debug info generated for Swift types with private or fileprivate access, because multiple such types of the same name may exist in different files due to Swift's scoping rules. This is not so for types imported from Clang, because access specifiers do not affect lexical scope in C/C++.

#80515 is a precursor to #80485 that does not modify the compiler. I'm including #80515 in this cherry-pick because it introduces a test case that #80485 builds upon.

Issue: rdar://148481025

Risk: Low. The only compiler adjustment in this patch is an additional check that avoids generating a discriminator for Clang decls. Any call to getFilePrivateScope() that used to happen successfully will continue to do so.

Testing: Added test to test suite

Original PRs: #80515, #80485

Reviewers: @egorzhdan @Xazax-hun @fahadnayyar

j-hui added 2 commits April 10, 2025 06:54
swiftlang#80485)

When generating debug symbols for private Clang types (which we started
importing recently), the compiler crashes due to an assertion failure
from ClangModuleUnit::getDiscriminatorForPrivateDecl(), which is called
by getFilePrivateScope().

This patch fixes the issue crash by not calling getFilePrivateScope()
for Clang types. A discriminator is usually needed to disambiguate
private Swift types declared in different files, but Clang types follow
different scoping conventions that make this discriminator unnecessary.

rdar://148481025
(cherry picked from commit dd2f465)
@j-hui j-hui requested a review from a team as a code owner April 10, 2025 14:25
@j-hui
Copy link
Contributor Author

j-hui commented Apr 10, 2025

@swift-ci please smoke test

@j-hui
Copy link
Contributor Author

j-hui commented Apr 11, 2025

@swift-ci please test

@j-hui
Copy link
Contributor Author

j-hui commented Apr 12, 2025

@swift-ci please test macos platform

Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thank you for the extensive tests on this corner case.

@j-hui j-hui merged commit d7b44f4 into swiftlang:release/6.2 Apr 16, 2025
5 checks passed
@j-hui j-hui deleted the fix-interop-private-debug-symbols-6.2 branch April 16, 2025 00:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants