From f41e52c88048213f5b1158c17d1c5ae752d09f56 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 6 Dec 2014 01:13:41 +0000 Subject: [PATCH] PR21217: Slightly more eagerly load -fmodule-map-file= files and provide diagnostics if they don't exist. Based on a patch by John Thompson! git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@223561 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Frontend/FrontendOptions.h | 3 +++ include/clang/Lex/HeaderSearchOptions.h | 3 --- lib/Frontend/CompilerInstance.cpp | 8 ++++++++ lib/Frontend/CompilerInvocation.cpp | 4 +--- lib/Lex/HeaderSearch.cpp | 12 ------------ 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index 4e93b4ee10..71c5aa47af 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -233,6 +233,9 @@ public: /// The list of plugins to load. std::vector Plugins; + /// \brief The list of module map files to load before processing the input. + std::vector ModuleMapFiles; + /// \brief The list of additional prebuilt module files to load before /// processing the input. std::vector ModuleFiles; diff --git a/include/clang/Lex/HeaderSearchOptions.h b/include/clang/Lex/HeaderSearchOptions.h index 06024b2e90..4e6e46939f 100644 --- a/include/clang/Lex/HeaderSearchOptions.h +++ b/include/clang/Lex/HeaderSearchOptions.h @@ -129,9 +129,6 @@ public: /// of computing the module hash. llvm::SetVector ModulesIgnoreMacros; - /// \brief The set of user-provided module-map-files. - llvm::SetVector ModuleMapFiles; - /// \brief The set of user-provided virtual filesystem overlay files. std::vector VFSOverlayFiles; diff --git a/lib/Frontend/CompilerInstance.cpp b/lib/Frontend/CompilerInstance.cpp index dcc824723a..a5165ad621 100644 --- a/lib/Frontend/CompilerInstance.cpp +++ b/lib/Frontend/CompilerInstance.cpp @@ -371,6 +371,14 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) { 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/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 65ffd5475c..f01663858e 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -848,6 +848,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, Opts.ASTDumpLookups = Args.hasArg(OPT_ast_dump_lookups); Opts.UseGlobalModuleIndex = !Args.hasArg(OPT_fno_modules_global_index); Opts.GenerateGlobalModuleIndex = Opts.UseGlobalModuleIndex; + Opts.ModuleMapFiles = Args.getAllArgValues(OPT_fmodule_map_file); Opts.ModuleFiles = Args.getAllArgValues(OPT_fmodule_file); Opts.CodeCompleteOpts.IncludeMacros @@ -1019,9 +1020,6 @@ static void ParseHeaderSearchArgs(HeaderSearchOptions &Opts, ArgList &Args) { StringRef MacroDef = (*it)->getValue(); Opts.ModulesIgnoreMacros.insert(MacroDef.split('=').first); } - std::vector ModuleMapFiles = - Args.getAllArgValues(OPT_fmodule_map_file); - Opts.ModuleMapFiles.insert(ModuleMapFiles.begin(), ModuleMapFiles.end()); // Add -I..., -F..., and -index-header-map options in order. bool IsIndexHeaderMap = false; diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index bbbcf3abec..a3f3737521 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -569,18 +569,6 @@ const FileEntry *HeaderSearch::LookupFile( 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(); -- 2.40.0