diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-07-21 23:54:07 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2015-07-21 23:54:07 +0000 |
commit | a534a31c5e73163eaa61560cd4e0c4c19bcbcfb1 (patch) | |
tree | 7e27c06c168865d3d0d300b93a015c414ba38bcc /clang/lib/Sema/SemaLookup.cpp | |
parent | 159e5ed9dc8f8107cbd32521e4e2436254f2b07e (diff) | |
download | bcm5719-llvm-a534a31c5e73163eaa61560cd4e0c4c19bcbcfb1.tar.gz bcm5719-llvm-a534a31c5e73163eaa61560cd4e0c4c19bcbcfb1.zip |
[modules] In C++, stop serializing and deserializing a list of declarations in
the identifier table. This is redundant, since the TU-scope lookups are also
serialized as part of the TU DeclContext, and wasteful in a number of ways. We
still emit the decls for PCH / preamble builds, since for those we want
identical results, not merely semantically equivalent ones.
llvm-svn: 242855
Diffstat (limited to 'clang/lib/Sema/SemaLookup.cpp')
-rw-r--r-- | clang/lib/Sema/SemaLookup.cpp | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp index 3fd1f21ba3f..99b945597bc 100644 --- a/clang/lib/Sema/SemaLookup.cpp +++ b/clang/lib/Sema/SemaLookup.cpp @@ -378,7 +378,7 @@ void LookupResult::resolveKind() { // Don't do any extra resolution if we've already resolved as ambiguous. if (ResultKind == Ambiguous) return; - llvm::SmallPtrSet<NamedDecl*, 16> Unique; + llvm::SmallDenseMap<NamedDecl*, unsigned, 16> Unique; llvm::SmallPtrSet<QualType, 16> UniqueTypes; bool Ambiguous = false; @@ -414,14 +414,26 @@ void LookupResult::resolveKind() { } } - if (!Unique.insert(D).second) { + auto UniqueResult = Unique.insert(std::make_pair(D, I)); + if (!UniqueResult.second) { // If it's not unique, pull something off the back (and // continue at this index). - // FIXME: This is wrong. We need to take the more recent declaration in - // order to get the right type, default arguments, etc. We also need to - // prefer visible declarations to hidden ones (for redeclaration lookup - // in modules builds). - Decls[I] = Decls[--N]; + auto ExistingI = UniqueResult.first->second; + auto *Existing = Decls[ExistingI]->getUnderlyingDecl(); + for (Decl *Prev = Decls[I]->getUnderlyingDecl()->getPreviousDecl(); /**/; + Prev = Prev->getPreviousDecl()) { + if (Prev == Existing) { + // Existing result is older. Replace it with the new one. + Decls[ExistingI] = Decls[I]; + Decls[I] = Decls[--N]; + break; + } + if (!Prev) { + // New decl is older. Keep the existing one. + Decls[I] = Decls[--N]; + break; + } + } continue; } |