-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix ASTMangler mangling NS_OPTION differently in C++ mode #64043
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
Conversation
7244342
to
b5eb7b7
Compare
lib/AST/ASTMangler.cpp
Outdated
// Use an anonymous enum's enclosing typedef for the mangled name, if | ||
// present. This matches C++'s rules for linkage names of tag declarations. | ||
if (namedDecl->getDeclName().isEmpty()) | ||
if (auto *tagDecl = dyn_cast<clang::TagDecl>(namedDecl)) | ||
if (auto *typedefDecl = tagDecl->getTypedefNameForAnonDecl()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little weird. I want to make the Clang AST look like the Objective-C definition so that the mangled name will be the same, but I don't want the mutation to persist beyond after the mangler is done with it. More specifically, I want the anonymous enum to no longer be anonymous and instead have the backing typedef's name.
I considered making a copy of the node, but that seems pretty wasteful. I'd have to copy at least once per NS_OPTION use and keep them around somewhere. Instead I've made this RAII container that just clears the anonymous enum's name after the client is done with it.
@swift-ci Please test |
@swift-ci Please test source compatibility suite |
@swift-ci Please Test Source Compatibility |
b5eb7b7
to
e3bf0ab
Compare
@swift-ci Please test |
@swift-ci Please Test Source Compatibility |
@swift-ci Please test macOS platform |
@swift-ci Please test Windows platform |
LGTM. I will merge once we get a chance to chat about this 1:1 this week. |
e3bf0ab
to
6a6b4f6
Compare
@swift-ci Please test |
@swift-ci Please test source compatibility |
Compat suite failures are unrelated. The change passed compat suite before, and I've only made non-functional changes since to address PR comments. |
6a6b4f6
to
508d5d6
Compare
@swift-ci Please test |
@swift-ci Please test source compatibility |
RAII AST meddling no more -- teach the mangler to handle it instead. |
@swift-ci Please test source compatibility |
CF_OPTIONS is defined differently in the SDK based on a __cplusplus preprocessor branch. As a result, declarations referencing CF_OPTIONS are mangled differently depending on if C++ interop is enabled. This meant a module compiled with cxx interop on could not be linked with a module compiled without and vice versa. This patch modifies the mangler such that the mangled names are consistent. This is achieved by feeding the mangler a modified AST node that looks like the Objective-C definition of CF_OPTIONS, even when we have cxx interop enabled.
508d5d6
to
709321b
Compare
@swift-ci Please test |
@swift-ci Please test source compatibility |
@swift-ci Please test macOS platform |
@swift-ci Please Test Source Compatibility Release |
… be desugared This patch is an add-on to swiftlang#64043. Essentially when encountering NS_OPTIONS enums, in C++-Interop mode if they are not specially handled then they can mangle differently than they do without C++-Interop. This patch adds logic to handle when a typedef and enum have additional clang::ElaboratedType sugar, but otherwise it does the same as the existing 64043 patch. The test case provided was encountered in a real app build. The problem came from when two modules are each compiled one with and one without C++-Interop. For the test case code provided the mangling of the protocol conformance is not consistent and the code in SILGenLazyConformance.cpp crashes on an invalid conformance with reason "Invalid conformance in type-checked AST".
… be desugared This patch is an add-on to swiftlang#64043. Essentially when encountering NS_OPTIONS enums, in C++-Interop mode if they are not specially handled then they can mangle differently than they do without C++-Interop. This patch adds logic to handle when a typedef and enum have additional clang::ElaboratedType sugar, but otherwise it does the same as the existing 64043 patch. The test case provided was encountered in a real app build. The problem came from when two modules are each compiled one with and one without C++-Interop. For the test case code provided the mangling of the protocol conformance is not consistent and the code in SILGenLazyConformance.cpp crashes on an invalid conformance with reason "Invalid conformance in type-checked AST".
… be desugared This patch is an add-on to swiftlang#64043. Essentially when encountering NS_OPTIONS enums, in C++-Interop mode if they are not specially handled then they can mangle differently than they do without C++-Interop. This patch adds logic to handle when a typedef and enum have additional clang::ElaboratedType sugar, but otherwise it does the same as the existing 64043 patch. The test case provided was encountered in a real app build. The problem came from when two modules are each compiled one with and one without C++-Interop. For the test case code provided the mangling of the protocol conformance is not consistent and the code in SILGenLazyConformance.cpp crashes on an invalid conformance with reason "Invalid conformance in type-checked AST".
… be desugared This patch is an add-on to swiftlang#64043. Essentially when encountering NS_OPTIONS enums, in C++-Interop mode if they are not specially handled then they can mangle differently than they do without C++-Interop. This patch adds logic to handle when a typedef and enum have additional clang::ElaboratedType sugar, but otherwise it does the same as the existing 64043 patch. The test case provided was encountered in a real app build. The problem came from when two modules are each compiled one with and one without C++-Interop. For the test case code provided the mangling of the protocol conformance is not consistent and the code in SILGenLazyConformance.cpp crashes on an invalid conformance with reason "Invalid conformance in type-checked AST". (cherry picked from commit fe6ccd7)
CF_OPTIONS is defined differently in the SDK based on a __cplusplus preprocessor branch. As a result, declarations referencing CF_OPTIONS are mangled differently depending on if C++ interop is enabled.
This meant a module compiled with cxx interop on could not be linked with a module compiled without and vice versa. This patch modifies the mangler such that the mangled names are consistent. This is achieved by feeding the mangler a modified AST node that looks like the Objective-C definition of CF_OPTIONS, even when we have cxx interop enabled.