summaryrefslogtreecommitdiffstats
path: root/lib/AST/DeclBase.cpp
diff options
context:
space:
mode:
authorManman Ren <manman.ren@gmail.com>2016-09-06 18:16:54 +0000
committerManman Ren <manman.ren@gmail.com>2016-09-06 18:16:54 +0000
commit12212b904597756dc22c66d91f8dd7b9b022fa97 (patch)
tree086580271dce43b7b48c7912671b2fd618b08ade /lib/AST/DeclBase.cpp
parentf43724c2b7a47a71ad9309666c606c6a4187a76c (diff)
Modules: Fix an assertion in DeclContext::buildLookup.
When calling getMostRecentDecl, we can pull in more definitions from a module. We call getPrimaryContext afterwards to make sure that we buildLookup on a primary context. rdar://27926200 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@280728 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclBase.cpp')
-rw-r--r--lib/AST/DeclBase.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 8342c0f2e3..4586d4bd2a 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -1411,10 +1411,6 @@ DeclContext::lookup(DeclarationName Name) const {
assert(DeclKind != Decl::LinkageSpec &&
"Should not perform lookups into linkage specs!");
- const DeclContext *PrimaryContext = getPrimaryContext();
- if (PrimaryContext != this)
- return PrimaryContext->lookup(Name);
-
// If we have an external source, ensure that any later redeclarations of this
// context have been loaded, since they may add names to the result of this
// lookup (or add external visible storage).
@@ -1422,6 +1418,12 @@ DeclContext::lookup(DeclarationName Name) const {
if (Source)
(void)cast<Decl>(this)->getMostRecentDecl();
+ // getMostRecentDecl can change the result of getPrimaryContext. Call
+ // getPrimaryContext afterwards.
+ const DeclContext *PrimaryContext = getPrimaryContext();
+ if (PrimaryContext != this)
+ return PrimaryContext->lookup(Name);
+
if (hasExternalVisibleStorage()) {
assert(Source && "external visible storage but no external source?");