Teach the preprocessor how to handle module import declarations that
involve submodules (e.g., importing std.vector), rather than always
importing the top-level module.
llvm-svn: 145478
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index dfc98e8..66b381e 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -1070,6 +1070,12 @@
ModuleKey CompilerInstance::loadModule(SourceLocation ImportLoc,
ModuleIdPath Path) {
+ // If we've already handled this import, just return the cached result.
+ // This one-element cache is important to eliminate redundant diagnostics
+ // when both the preprocessor and parser see the same import declaration.
+ if (!ImportLoc.isInvalid() && LastModuleImportLoc == ImportLoc)
+ return LastModuleImportResult.getOpaqueValue();
+
// Determine what file we're searching from.
SourceManager &SourceMgr = getSourceManager();
SourceLocation ExpandedImportLoc = SourceMgr.getExpansionLoc(ImportLoc);
@@ -1241,6 +1247,8 @@
// FIXME: The module file's FileEntry makes a poor key indeed! Once we
// eliminate the need for FileEntry here, the module itself will become the
// key (which does make sense).
+ LastModuleImportLoc = ImportLoc;
+ LastModuleImportResult = Known;
return Known.getOpaqueValue();
}