Index: include/clang/Basic/DiagnosticLexKinds.td =================================================================== --- include/clang/Basic/DiagnosticLexKinds.td +++ include/clang/Basic/DiagnosticLexKinds.td @@ -550,6 +550,8 @@ ShowInSystemHeader, DefaultIgnore, InGroup>; // Module map parsing +def err_module_map_opt_not_found : Error< + "file '%0' specified via -fmodule-map-file not found">; def err_mmap_unknown_token : Error<"skipping stray token">; def err_mmap_expected_module : Error<"expected module declaration">; def err_mmap_expected_module_name : Error<"expected module name">; Index: lib/Lex/HeaderSearch.cpp =================================================================== --- lib/Lex/HeaderSearch.cpp +++ lib/Lex/HeaderSearch.cpp @@ -62,6 +62,21 @@ NumFrameworkLookups = NumSubFrameworkLookups = 0; EnabledModules = LangOpts.Modules; + + if (!HSOpts->ModuleMapFiles.empty()) { + // Preload all explicitly specified module map files. This enables modules + // map files lying in a directory structure separate from the header files + // that they describe. These cannot be loaded lazily upon encountering a + // header file, as there is no other known mapping from a header file to its + // module map file. + for (const auto &Filename : HSOpts->ModuleMapFiles) { + if (const FileEntry *File = FileMgr.getFile(Filename)) + loadModuleMapFile(File, /*IsSystem=*/false); + else + Diags.Report(diag::err_module_map_opt_not_found) << Filename; + } + HSOpts->ModuleMapFiles.clear(); + } } HeaderSearch::~HeaderSearch() { @@ -569,18 +584,6 @@ ArrayRef> Includers, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool SkipCache) { - if (!HSOpts->ModuleMapFiles.empty()) { - // Preload all explicitly specified module map files. This enables modules - // map files lying in a directory structure separate from the header files - // that they describe. These cannot be loaded lazily upon encountering a - // header file, as there is no other known mapping from a header file to its - // module map file. - for (const auto &Filename : HSOpts->ModuleMapFiles) - if (const FileEntry *File = FileMgr.getFile(Filename)) - loadModuleMapFile(File, /*IsSystem=*/false); - HSOpts->ModuleMapFiles.clear(); - } - if (SuggestedModule) *SuggestedModule = ModuleMap::KnownHeader(); Index: test/Modules/pr21217.cpp =================================================================== --- test/Modules/pr21217.cpp +++ test/Modules/pr21217.cpp @@ -0,0 +1,6 @@ +// RUN: not %clang_cc1 -fmodules -fmodule-map-file=does-not-exist.modulemap -verify %s 2>&1 | \ +// RUN: FileCheck %s + +// CHECK: file 'does-not-exist.modulemap' specified via -fmodule-map-file not found + +#include "Inputs/private/common.h"