[ClangImporter] Handle macros that are undefined and then redefined #12413
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This includes
LONG_MAX
in the Darwin module, which is defined by the system and then immediately redefined by Clang's copy of limits.h.The general strategy here is that if two definitions of a macro in the same module are in separate explicit submodules, we need to keep track of both of them, but if they're in the same explicit submodule then one is probably deliberately redefining the other. This isn't fully correct because one explicit submodule could include another explicit submodule, but it's a good first approximation, which we can refine if we come across problem cases in practice.
Swift also has the ability to distinguish between ModuleA.MACRO and ModuleB.MACRO if you've imported both modules, although there's an issue that the two of them end up getting the same mangled name if you try to use both in the same compilation unit. (Filed rdar://problem/34968281.) That ability is preserved with this change.
All of this will likely change if/when we switch to Clang's "local submodule visibility" mode, which is needed for the C++ Modules TS but is also incompatible with Apple's SDKs at the moment. In that case, macros in two separate explicit submodules will no longer have an 'override' relationship just because they're mentioned sequentially in the module map.
rdar://problem/34413934