diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -807,12 +807,14 @@ goto failure; // 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 (CI.getLangOpts().Modules) { + 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; + } } // Add a module declaration scope so that modules from -fmodule-map-file