Fix errors like
clang/test/Modules/redefinition-c-tagtypes.m:36:10: error: reference to 'FST' is ambiguous return FST; ^ clang/test/Modules/redefinition-c-tagtypes.m:24:3: note: candidate found by name lookup is 'FST' FST = 22, ^ clang/test/Modules/Inputs/F.framework/PrivateHeaders/NS.h:7:3: note: candidate found by name lookup is 'FST' FST = 22, ^
The name lookup is ambiguous because we have 2 EnumConstantDecl for the
same identifier - one from hidden submodule, another non-modular from .m
file. One way to avoid ambiguity is for decls to have the same canonical
decl. But in this case the hidden decl is deserialized during lexing,
right before non-modular decl is created. So ASTDeclReader cannot do
anything useful in mergeMergeable(Mergeable<EnumConstantDecl>*) and
cannot make different decls have the same canonical decl.
The fix is roughly a follow-up to D31778. As a duplicate non-modular
EnumDecl is dropped, we are dropping its constants too and remove them
from the global name lookup. Another option was to avoid adding
EnumConstantDecl to IdResolver when we know they are parsed for
comparison only. But we still need that global name lookup for constants
referencing other constants from the same enum, like MinXOther = MinX.
So instead we remove the constants after ParseEnumBody is done.