Skip to content
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

[ASTMangler] Mangle nested imported error structs correctly #24804

Merged
merged 1 commit into from May 15, 2019

Conversation

Projects
None yet
3 participants
@brentdax
Copy link
Collaborator

commented May 15, 2019

Error structs synthesized by ClangImporter can be renamed using SWIFT_NAME() to syntactically appear anywhere in the type hierarchy with any name, but they should always be mangled as __C_Synthesized.related decl ‘e’ of <clang enum name>. Unfortunately, when SWIFT_NAME() was used to nest the error struct inside another type, an ASTMangler bug would cause it to be mangled as <parent type>.related decl ‘e’ of <clang enum name>, and an ASTDemangler bug would also require a valid parent type. This created a mismatch between the compiler’s and runtime’s manglings which caused crashes when you tried to match the imported error struct in a catch.

This PR corrects the compiler bugs so that it generates the mangling the runtime expects. This is theoretically ABI-breaking, but as far as I can determine nobody has shipped the incorrectly mangled names, presumably because they crash when you try to use them.

Fixes rdar://problem/48040880.

(This PR does not affect the mangling of error types written in Swift, only ones imported from Clang.)

[ASTMangler] Mangle nested imported error structs correctly
Error structs synthesized by ClangImporter can be renamed using SWIFT_NAME() to syntactically appear anywhere in the type hierarchy with any name, but they should always be mangled as `__C_Synthesized.related decl ‘e’ of <Objective-C enum name>`. Unforunately, when SWIFT_NAME() was used to nest the error struct inside another type, an ASTMangler bug would cause it to be mangled as `<parent type>.related decl ‘e’ of <Objective-C enum name>`, and an ASTDemangler bug would also require a valid parent type. This created a mismatch between the compiler’s and runtime’s manglings which caused crashes when you tried to match the imported error struct in a `catch`.

This PR corrects the compiler bugs so that it generates the mangling the runtime expects. This is theoretically ABI-breaking, but as far as I can determine nobody has shipped the incorrectly mangled names, presumably because they crash when you try to use them.

Fixes <rdar://problem/48040880>.
@brentdax

This comment has been minimized.

Copy link
Collaborator Author

commented May 15, 2019

@swift-ci please test

@brentdax brentdax requested review from slavapestov and jrose-apple May 15, 2019

@jrose-apple
Copy link
Member

left a comment

Nice work!

@brentdax brentdax merged commit 36024b6 into apple:master May 15, 2019

4 checks passed

Swift Test Linux Platform No test results found.
Details
Swift Test Linux Platform (smoke test)
Details
Swift Test OS X Platform No test results found.
Details
Swift Test OS X Platform (smoke test)
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.