summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-03-24 02:44:20 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-03-24 02:44:20 +0000
commit18b380b1e524a9818ac2046fd9f28d2b1be7d9d6 (patch)
treed63de7848e0fdf269bbc166df18cacaa8d6a0299
parent6279a07eaacb06ba250188ee8ade05b8a88b1d94 (diff)
downloadbcm5719-llvm-18b380b1e524a9818ac2046fd9f28d2b1be7d9d6.tar.gz
bcm5719-llvm-18b380b1e524a9818ac2046fd9f28d2b1be7d9d6.zip
When looking for lexical decls from an external source, check all contexts
rather than just the primary context. This is technically correct but results in no functionality change (in Clang nor LLDB) because all users of this functionality only use it on single-context DCs. llvm-svn: 233045
-rw-r--r--clang/include/clang/AST/DeclBase.h2
-rw-r--r--clang/lib/AST/DeclBase.cpp36
2 files changed, 22 insertions, 16 deletions
diff --git a/clang/include/clang/AST/DeclBase.h b/clang/include/clang/AST/DeclBase.h
index 7088e4a8d15..3c61c1ea833 100644
--- a/clang/include/clang/AST/DeclBase.h
+++ b/clang/include/clang/AST/DeclBase.h
@@ -1722,7 +1722,7 @@ public:
private:
void reconcileExternalVisibleStorage() const;
- void LoadLexicalDeclsFromExternalStorage() const;
+ bool LoadLexicalDeclsFromExternalStorage() const;
/// @brief Makes a declaration visible within this context, but
/// suppresses searches for external declarations with the same
diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 1f08a64d3ab..87d0b3912f7 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1020,7 +1020,8 @@ void DeclContext::reconcileExternalVisibleStorage() const {
/// \brief Load the declarations within this lexical storage from an
/// external source.
-void
+/// \return \c true if any declarations were added.
+bool
DeclContext::LoadLexicalDeclsFromExternalStorage() const {
ExternalASTSource *Source = getParentASTContext().getExternalSource();
assert(hasExternalLexicalStorage() && Source && "No external storage?");
@@ -1028,26 +1029,20 @@ DeclContext::LoadLexicalDeclsFromExternalStorage() const {
// Notify that we have a DeclContext that is initializing.
ExternalASTSource::Deserializing ADeclContext(Source);
- ExternalLexicalStorage = false;
- bool HadLazyExternalLexicalLookups = HasLazyExternalLexicalLookups;
- HasLazyExternalLexicalLookups = false;
-
// Load the external declarations, if any.
SmallVector<Decl*, 64> Decls;
+ ExternalLexicalStorage = false;
switch (Source->FindExternalLexicalDecls(this, Decls)) {
case ELR_Success:
break;
case ELR_Failure:
case ELR_AlreadyLoaded:
- return;
+ return false;
}
if (Decls.empty())
- return;
-
- if (HadLazyExternalLexicalLookups)
- HasLazyLocalLexicalLookups = true;
+ return false;
// We may have already loaded just the fields of this record, in which case
// we need to ignore them.
@@ -1064,6 +1059,7 @@ DeclContext::LoadLexicalDeclsFromExternalStorage() const {
FirstDecl = ExternalFirst;
if (!LastDecl)
LastDecl = ExternalLast;
+ return true;
}
DeclContext::lookup_result
@@ -1272,13 +1268,23 @@ StoredDeclsMap *DeclContext::buildLookup() {
if (!HasLazyLocalLexicalLookups && !HasLazyExternalLexicalLookups)
return LookupPtr;
- if (HasLazyExternalLexicalLookups)
- LoadLexicalDeclsFromExternalStorage();
-
SmallVector<DeclContext *, 2> Contexts;
collectAllContexts(Contexts);
- for (unsigned I = 0, N = Contexts.size(); I != N; ++I)
- buildLookupImpl(Contexts[I], hasExternalVisibleStorage());
+
+ if (HasLazyExternalLexicalLookups) {
+ HasLazyExternalLexicalLookups = false;
+ for (auto *DC : Contexts) {
+ if (DC->hasExternalLexicalStorage())
+ HasLazyLocalLexicalLookups |=
+ DC->LoadLexicalDeclsFromExternalStorage();
+ }
+
+ if (!HasLazyLocalLexicalLookups)
+ return LookupPtr;
+ }
+
+ for (auto *DC : Contexts)
+ buildLookupImpl(DC, hasExternalVisibleStorage());
// We no longer have any lazy decls.
HasLazyLocalLexicalLookups = false;
OpenPOWER on IntegriCloud