]> granicus.if.org Git - clang/commit
[modules] Simplify module macro handling in non-local-submodule-visibility mode.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 19 May 2017 23:32:38 +0000 (23:32 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 19 May 2017 23:32:38 +0000 (23:32 +0000)
commit838eab83af5727fd23b3d052368e2c3bbe3be2a6
treef7d6be9e4e21a5b1d667432b0ea71433c9383b03
parent273b25e491a98a58481085a7fb3766c5116ffd4c
[modules] Simplify module macro handling in non-local-submodule-visibility mode.

When reaching the end of a module, we used to convert its macros to
ModuleMacros but also leave them in the MacroDirective chain for the
identifier. This meant that every lookup of such a macro would find two
(identical) definitions. It also made it difficult to determine the correct
owner for a macro when reaching the end of a module: the most recent
MacroDirective in the chain could be from an #included submodule rather than
the current module.

Simplify this: whenever we convert a MacroDirective to a ModuleMacro when
leaving a module, clear out the MacroDirective chain for that identifier, and
just rely on the ModuleMacro to provide the macro definition information.

(We don't want to do this for local submodule visibility mode, because in that
mode we maintain a distinct MacroDirective chain for each submodule, and we
need to keep around the prior MacroDirective in case we re-enter the submodule
-- for instance, if its header is #included more than once in a module build,
we need the include guard directive to stick around. But the problem doesn't
arise in this case for the same reason: each submodule has its own
MacroDirective chain, so the macros don't leak out of submodules in the first
place.)

This reinstates r302932, reverted in r302947, with a fix for a bug that
resulted in us sometimes losing macro definitions due to failing to clear out
the overridden module macro list when promoting a directive to a module macro.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303468 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Lex/PPLexerChange.cpp
test/Modules/macro-redefinition.cpp [new file with mode: 0644]