summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/DeclBase.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-02-08 00:37:45 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-02-08 00:37:45 +0000
commit75fc3bf5fe9ad5ad38492902b07ede50de3f18d4 (patch)
treee121f71514620a61cb040bd3498c9f3dc0a00c04 /clang/lib/AST/DeclBase.cpp
parente4c7e855f118a9f44af46fbd2e6a17c9c1745a21 (diff)
downloadbcm5719-llvm-75fc3bf5fe9ad5ad38492902b07ede50de3f18d4.tar.gz
bcm5719-llvm-75fc3bf5fe9ad5ad38492902b07ede50de3f18d4.zip
Fix stack overflow and improve performance when a module contains many
overloads of a name by claiming that there are no lookup results for that name in modules while loading the names from the module. Lookups in deserialization really don't want to find names which they themselves are in the process of introducing. This also has the pleasant side-effect of automatically caching PCH lookups which found no names. The runtime here is still quadratic in the number of overloads, but the constant is lower. llvm-svn: 174685
Diffstat (limited to 'clang/lib/AST/DeclBase.cpp')
-rw-r--r--clang/lib/AST/DeclBase.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 3039c954626..e1202c23a84 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1203,14 +1203,16 @@ DeclContext::lookup(DeclarationName Name) {
if (LookupPtr.getInt())
Map = buildLookup();
+ if (!Map)
+ Map = CreateStoredDeclsMap(getParentASTContext());
+
// If a PCH/module has a result for this name, and we have a local
// declaration, we will have imported the PCH/module result when adding the
// local declaration or when reconciling the module.
- if (Map) {
- StoredDeclsMap::iterator I = Map->find(Name);
- if (I != Map->end())
- return I->second.getLookupResult();
- }
+ std::pair<StoredDeclsMap::iterator, bool> R =
+ Map->insert(std::make_pair(Name, StoredDeclsList()));
+ if (!R.second)
+ return R.first->second.getLookupResult();
ExternalASTSource *Source = getParentASTContext().getExternalSource();
if (Source->FindExternalVisibleDeclsByName(this, Name)) {
OpenPOWER on IntegriCloud