diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/Lex/HeaderSearch.cpp')
-rw-r--r-- | contrib/llvm-project/clang/lib/Lex/HeaderSearch.cpp | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/contrib/llvm-project/clang/lib/Lex/HeaderSearch.cpp b/contrib/llvm-project/clang/lib/Lex/HeaderSearch.cpp index 1df28cc07209..99c92e91aad5 100644 --- a/contrib/llvm-project/clang/lib/Lex/HeaderSearch.cpp +++ b/contrib/llvm-project/clang/lib/Lex/HeaderSearch.cpp @@ -164,14 +164,39 @@ std::string HeaderSearch::getPrebuiltModuleFileName(StringRef ModuleName, return {}; } +std::string HeaderSearch::getPrebuiltImplicitModuleFileName(Module *Module) { + const FileEntry *ModuleMap = + getModuleMap().getModuleMapFileForUniquing(Module); + StringRef ModuleName = Module->Name; + StringRef ModuleMapPath = ModuleMap->getName(); + StringRef ModuleCacheHash = HSOpts->DisableModuleHash ? "" : getModuleHash(); + for (const std::string &Dir : HSOpts->PrebuiltModulePaths) { + SmallString<256> CachePath(Dir); + llvm::sys::fs::make_absolute(CachePath); + llvm::sys::path::append(CachePath, ModuleCacheHash); + std::string FileName = + getCachedModuleFileNameImpl(ModuleName, ModuleMapPath, CachePath); + if (!FileName.empty() && getFileMgr().getFile(FileName)) + return FileName; + } + return {}; +} + std::string HeaderSearch::getCachedModuleFileName(StringRef ModuleName, StringRef ModuleMapPath) { + return getCachedModuleFileNameImpl(ModuleName, ModuleMapPath, + getModuleCachePath()); +} + +std::string HeaderSearch::getCachedModuleFileNameImpl(StringRef ModuleName, + StringRef ModuleMapPath, + StringRef CachePath) { // If we don't have a module cache path or aren't supposed to use one, we // can't do anything. - if (getModuleCachePath().empty()) + if (CachePath.empty()) return {}; - SmallString<256> Result(getModuleCachePath()); + SmallString<256> Result(CachePath); llvm::sys::fs::make_absolute(Result); if (HSOpts->DisableModuleHash) { @@ -765,8 +790,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( // This is the header that MSVC's header search would have found. ModuleMap::KnownHeader MSSuggestedModule; - const FileEntry *MSFE_FE = nullptr; - StringRef MSFE_Name; + Optional<FileEntryRef> MSFE; // Unless disabled, check to see if the file is in the #includer's // directory. This cannot be based on CurDir, because each includer could be @@ -841,8 +865,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( if (Diags.isIgnored(diag::ext_pp_include_search_ms, IncludeLoc)) { return FE; } else { - MSFE_FE = &FE->getFileEntry(); - MSFE_Name = FE->getName(); + MSFE = FE; if (SuggestedModule) { MSSuggestedModule = *SuggestedModule; *SuggestedModule = ModuleMap::KnownHeader(); @@ -854,9 +877,6 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( } } - Optional<FileEntryRef> MSFE(MSFE_FE ? FileEntryRef(MSFE_Name, *MSFE_FE) - : Optional<FileEntryRef>()); - CurDir = nullptr; // If this is a system #include, ignore the user #include locs. @@ -1167,12 +1187,12 @@ HeaderFileInfo &HeaderSearch::getFileInfo(const FileEntry *FE) { HeaderFileInfo *HFI = &FileInfo[FE->getUID()]; // FIXME: Use a generation count to check whether this is really up to date. if (ExternalSource && !HFI->Resolved) { - HFI->Resolved = true; auto ExternalHFI = ExternalSource->GetHeaderFileInfo(FE); - - HFI = &FileInfo[FE->getUID()]; - if (ExternalHFI.External) - mergeHeaderFileInfo(*HFI, ExternalHFI); + if (ExternalHFI.IsValid) { + HFI->Resolved = true; + if (ExternalHFI.External) + mergeHeaderFileInfo(*HFI, ExternalHFI); + } } HFI->IsValid = true; @@ -1199,12 +1219,12 @@ HeaderSearch::getExistingFileInfo(const FileEntry *FE, if (!WantExternal && (!HFI->IsValid || HFI->External)) return nullptr; if (!HFI->Resolved) { - HFI->Resolved = true; auto ExternalHFI = ExternalSource->GetHeaderFileInfo(FE); - - HFI = &FileInfo[FE->getUID()]; - if (ExternalHFI.External) - mergeHeaderFileInfo(*HFI, ExternalHFI); + if (ExternalHFI.IsValid) { + HFI->Resolved = true; + if (ExternalHFI.External) + mergeHeaderFileInfo(*HFI, ExternalHFI); + } } } else if (FE->getUID() >= FileInfo.size()) { return nullptr; |