if (PrimaryContext != this)
return PrimaryContext->lookup(Name);
- // If this is a namespace, ensure that any later redeclarations of it have
- // been loaded, since they may add names to the result of this lookup.
- if (auto *ND = dyn_cast<NamespaceDecl>(this))
- (void)ND->getMostRecentDecl();
+ // 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).
+ ExternalASTSource *Source = getParentASTContext().getExternalSource();
+ if (Source)
+ (void)cast<Decl>(this)->getMostRecentDecl();
if (hasExternalVisibleStorage()) {
+ assert(Source && "external visible storage but no external source?");
+
if (NeedToReconcileExternalVisibleStorage)
reconcileExternalVisibleStorage();
if (!R.second && !R.first->second.hasExternalDecls())
return R.first->second.getLookupResult();
- ExternalASTSource *Source = getParentASTContext().getExternalSource();
if (Source->FindExternalVisibleDeclsByName(this, Name) || !R.second) {
if (StoredDeclsMap *Map = LookupPtr.getPointer()) {
StoredDeclsMap::iterator I = Map->find(Name);
bool needsImportVisitation() const override { return true; }
void visitImport(StringRef FileName) override {
- if (!CI.ExplicitlyLoadedModuleFiles.insert(FileName).second)
+ if (!CI.ExplicitlyLoadedModuleFiles.insert(FileName).second) {
+ if (ModuleFileStack.size() == 0)
+ TopFileIsModule = true;
return;
+ }
ModuleFileStack.push_back(FileName);
if (ASTReader::readASTFileControlBlock(FileName, CI.getFileManager(),
--- /dev/null
+// RUN: rm -rf %t
+
+// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodule-name=b -o %t/b.pcm -fmodule-maps \
+// RUN: -emit-module %S/Inputs/merge-decl-context/merge-decl-context.modulemap -I%S/Inputs \
+// RUN: -I %S/Inputs/merge-decl-context
+// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodule-name=c -o %t/c.pcm -fmodule-maps \
+// RUN: -fmodule-file=%t/b.pcm \
+// RUN: -emit-module %S/Inputs/merge-decl-context/merge-decl-context.modulemap -I%S/Inputs \
+// RUN: -I %S/Inputs/merge-decl-context
+
+// Use the two modules in a single compile.
+// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodule-file=%t/c.pcm -fmodule-file=%t/b.pcm \
+// RUN: -fmodule-map-file=%S/Inputs/merge-decl-context/merge-decl-context.modulemap -I%S/Inputs \
+// RUN: -emit-llvm -o %t/test.o %s
+
+#include "Inputs/merge-decl-context/a.h"
+#include "Inputs/merge-decl-context/b.h"
+#include "Inputs/merge-decl-context/c.h"
+
+void t() {
+ ff(42);
+}
+
+