Skip to content

[ClangImporter] Handle macros that are undefined and then redefined #12413

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

jrose-apple
Copy link
Contributor

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

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
@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

Copy link
Contributor

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

Nice testcases :-)
LGTM

@jrose-apple jrose-apple merged commit b53967f into swiftlang:master Oct 13, 2017
@jrose-apple jrose-apple deleted the no-really-we-know-how-big-each-datatype-is branch October 13, 2017 22: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.

2 participants