]> granicus.if.org Git - clang/commitdiff
[modules] Remove temporary IdentifierInfo lookup results when we're done with them.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 20 Mar 2015 21:56:50 +0000 (21:56 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 20 Mar 2015 21:56:50 +0000 (21:56 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@232853 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Serialization/ASTReader.h
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTReaderDecl.cpp
test/Modules/linkage-merge.cpp

index 55fe0ef5971c340ab2e4cf80c18a0e7f7fc536dc..1b93702e1be10950c90f036659dc3025e64795f6 100644 (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;
index 93544ef20fc23345ca2336185d0b3deb56684c77..bd54779513e03a6dbed1255d2e1c8cde1e48a3e2 100644 (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);
index 83882a836939f896f5a07938724f43c26fb75118..9c3776268d944675bcf6e69796bdad8e522bb022 100644 (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
index 99917897fccf43769c55d0d49aa4f575980d7a56..3ac8053761bf8cee527256c2f3a17c70e4580359 100644 (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}}