diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 7 | ||||
| -rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 1 | ||||
| -rw-r--r-- | clang/lib/Frontend/FrontendActions.cpp | 13 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 3 |
4 files changed, 21 insertions, 3 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 8954c8fb9f0..32894f2eb56 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -678,6 +678,13 @@ void SourceManager::disableFileContentsOverride(const FileEntry *File) { OverriddenFilesInfo->OverriddenFilesWithBuffer.erase(File); } +void SourceManager::embedFileContentsInModule(const FileEntry *File) { + // We model an embedded file as a file whose buffer has been overridden + // by its contents as they are now. + const SrcMgr::ContentCache *CC = getOrCreateContentCache(File); + const_cast<SrcMgr::ContentCache *>(CC)->BufferOverridden = true; +} + StringRef SourceManager::getBufferData(FileID FID, bool *Invalid) const { bool MyInvalid = false; const SLocEntry &SLoc = getSLocEntry(FID, &MyInvalid); diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 73febb463ec..f078b37c3c2 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -960,6 +960,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, Opts.GenerateGlobalModuleIndex = Opts.UseGlobalModuleIndex; Opts.ModuleMapFiles = Args.getAllArgValues(OPT_fmodule_map_file); Opts.ModuleFiles = Args.getAllArgValues(OPT_fmodule_file); + Opts.ModulesEmbedFiles = Args.getAllArgValues(OPT_fmodules_embed_file_EQ); Opts.CodeCompleteOpts.IncludeMacros = Args.hasArg(OPT_code_completion_macros); diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 40277bdaa52..057361811ba 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -268,8 +268,9 @@ collectModuleHeaderIncludes(const LangOptions &LangOpts, FileManager &FileMgr, bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI, StringRef Filename) { - // Find the module map file. - const FileEntry *ModuleMap = CI.getFileManager().getFile(Filename); + // Find the module map file. + const FileEntry *ModuleMap = + CI.getFileManager().getFile(Filename, /*openFile*/true); if (!ModuleMap) { CI.getDiagnostics().Report(diag::err_module_map_not_found) << Filename; @@ -291,6 +292,14 @@ bool GenerateModuleAction::BeginSourceFileAction(CompilerInstance &CI, return false; } + // Set up embedding for any specified files. + for (const auto &F : CI.getFrontendOpts().ModulesEmbedFiles) { + if (const auto *FE = CI.getFileManager().getFile(F, /*openFile*/true)) + CI.getSourceManager().embedFileContentsInModule(FE); + else + CI.getDiagnostics().Report(diag::err_modules_embed_file_not_found) << F; + } + // If we're being run from the command-line, the module build stack will not // have been filled in yet, so complete it now in order to allow us to detect // module cycles. diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 87db6d3b4de..547dda73f73 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1023,7 +1023,8 @@ bool ASTReader::ReadVisibleDeclContextStorage(ModuleFile &M, void ASTReader::Error(StringRef Msg) { Error(diag::err_fe_pch_malformed, Msg); - if (Context.getLangOpts().Modules && !Diags.isDiagnosticInFlight()) { + if (Context.getLangOpts().Modules && !Diags.isDiagnosticInFlight() && + !PP.getHeaderSearchInfo().getModuleCachePath().empty()) { Diag(diag::note_module_cache_path) << PP.getHeaderSearchInfo().getModuleCachePath(); } |

