[modules] Remove temporary IdentifierInfo lookup results when we're done with them.

llvm-svn: 232853
This commit is contained in:
Richard Smith 2015-03-20 21:56:50 +00:00
parent ccf5f24b7b
commit 5a07892dec
4 changed files with 23 additions and 7 deletions

View File

@ -948,6 +948,11 @@ private:
llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4> >
PendingIdentifierInfos;
/// \brief The set of lookup results that we have faked in order to support
/// merging of partially deserialized decls but that we have not yet removed.
llvm::MapVector<IdentifierInfo *, SmallVector<NamedDecl*, 2> >
PendingFakeLookupResults;
/// \brief The generation number of each identifier, which keeps track of
/// the last time we loaded information about this identifier.
llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;

View File

@ -8627,7 +8627,15 @@ void ASTReader::FinishedDeserializing() {
}
void ASTReader::pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name) {
D = D->getMostRecentDecl();
if (IdentifierInfo *II = Name.getAsIdentifierInfo()) {
// Remove any fake results before adding any real ones.
auto It = PendingFakeLookupResults.find(II);
if (It != PendingFakeLookupResults.end()) {
for (auto *ND : PendingFakeLookupResults[II])
SemaObj->IdResolver.RemoveDecl(ND);
PendingFakeLookupResults.erase(It);
}
}
if (SemaObj->IdResolver.tryAddTopLevelDecl(D, Name) && SemaObj->TUScope) {
SemaObj->TUScope->AddDecl(D);

View File

@ -2621,8 +2621,11 @@ ASTDeclReader::FindExistingResult::~FindExistingResult() {
if (needsAnonymousDeclarationNumber(New)) {
setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(),
AnonymousDeclNumber, New);
} else if (DC->isTranslationUnit() && Reader.SemaObj) {
Reader.SemaObj->IdResolver.tryAddTopLevelDecl(New, Name);
} else if (DC->isTranslationUnit() && Reader.SemaObj &&
!Reader.getContext().getLangOpts().CPlusPlus) {
if (Reader.SemaObj->IdResolver.tryAddTopLevelDecl(New, Name))
Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()]
.push_back(New);
} else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
// Add the declaration to its redeclaration context so later merging
// lookups will find it.
@ -2727,7 +2730,8 @@ ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) {
if (isSameEntity(Existing, D))
return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
TypedefNameForLinkage);
} else if (DC->isTranslationUnit() && Reader.SemaObj) {
} else if (DC->isTranslationUnit() && Reader.SemaObj &&
!Reader.getContext().getLangOpts().CPlusPlus) {
IdentifierResolver &IdResolver = Reader.SemaObj->IdResolver;
// Temporarily consider the identifier to be up-to-date. We don't want to

View File

@ -11,6 +11,5 @@ static void g(int);
// happen to find lookup results for 'g'; LookupResult::resolveKind needs to
// be taught to prefer a visible result over a non-visible one.
//
// FIXME-error@-1 {{functions that differ only in their return type cannot be overloaded}}
// FIXME-note@Inputs/linkage-merge-foo.h:2 {{previous declaration is here}}
// expected-no-diagnostics
// expected-error@9 {{functions that differ only in their return type cannot be overloaded}}
// expected-note@Inputs/linkage-merge-foo.h:2 {{previous declaration is here}}