PR22299: Relocate code for handling -fmodule-map-file= so that we don't try to
produce diagnostics with source locations before the diagnostics system is
ready for them.

llvm-svn: 226882
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index 93a34b7..041a1e9 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -371,14 +371,6 @@
     AttachHeaderIncludeGen(*PP, /*ShowAllHeaders=*/false, /*OutputPath=*/"",
                            /*ShowDepth=*/true, /*MSStyle=*/true);
   }
-
-  // Load all explictly-specified module map files.
-  for (const auto &Filename : getFrontendOpts().ModuleMapFiles) {
-    if (auto *File = getFileManager().getFile(Filename))
-      PP->getHeaderSearchInfo().loadModuleMapFile(File, /*IsSystem*/false);
-    else
-      getDiagnostics().Report(diag::err_module_map_not_found) << Filename;
-  }
 }
 
 // ASTContext
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index c81c81a..0bb5d87 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -383,6 +383,15 @@
            "doesn't support modules");
   }
 
+  // If we were asked to load any module map files, do so now.
+  for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) {
+    if (auto *File = CI.getFileManager().getFile(Filename))
+      CI.getPreprocessor().getHeaderSearchInfo().loadModuleMapFile(
+          File, /*IsSystem*/false);
+    else
+      CI.getDiagnostics().Report(diag::err_module_map_not_found) << Filename;
+  }
+
   // If we were asked to load any module files, do so now.
   for (const auto &ModuleFile : CI.getFrontendOpts().ModuleFiles)
     if (!CI.loadModuleFile(ModuleFile))