diff options
Diffstat (limited to 'clang/lib/Basic/FileManager.cpp')
-rw-r--r-- | clang/lib/Basic/FileManager.cpp | 40 |
1 files changed, 8 insertions, 32 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index b66780a1d1d1..e8d0f20019eb 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -31,6 +31,7 @@ #include <climits> #include <cstdint> #include <cstdlib> +#include <optional> #include <string> #include <utility> @@ -123,7 +124,7 @@ FileManager::getDirectoryRef(StringRef DirName, bool CacheFailure) { DirName != llvm::sys::path::root_path(DirName) && llvm::sys::path::is_separator(DirName.back())) DirName = DirName.substr(0, DirName.size()-1); - Optional<std::string> DirNameStr; + std::optional<std::string> DirNameStr; if (is_style_windows(llvm::sys::path::Style::native)) { // Fixing a problem with "clang C:test.c" on Windows. // Stat("C:") does not recognize "C:" as a valid directory @@ -212,13 +213,7 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { if (!SeenFileInsertResult.first->second) return llvm::errorCodeToError( SeenFileInsertResult.first->second.getError()); - // Construct and return and FileEntryRef, unless it's a redirect to another - // filename. - FileEntryRef::MapValue Value = *SeenFileInsertResult.first->second; - if (LLVM_LIKELY(Value.V.is<FileEntry *>())) - return FileEntryRef(*SeenFileInsertResult.first); - return FileEntryRef(*reinterpret_cast<const FileEntryRef::MapEntry *>( - Value.V.get<const void *>())); + return FileEntryRef(*SeenFileInsertResult.first); } // We've not seen this before. Fill it in. @@ -274,8 +269,8 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { if (!UFE) UFE = new (FilesAlloc.Allocate()) FileEntry(); - if (Status.getName() == Filename) { - // The name matches. Set the FileEntry. + if (!Status.ExposesExternalVFSPath || Status.getName() == Filename) { + // Use the requested name. Set the FileEntry. NamedFileEnt->second = FileEntryRef::MapValue(*UFE, DirInfo); } else { // Name mismatch. We need a redirect. First grab the actual entry we want @@ -292,25 +287,9 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { // filesystems behave and confuses parts of clang expect to see the // name-as-accessed on the \a FileEntryRef. // - // Further, it isn't *just* external names, but will also give back absolute - // paths when a relative path was requested - the check is comparing the - // name from the status, which is passed an absolute path resolved from the - // current working directory. `clang-apply-replacements` appears to depend - // on this behaviour, though it's adjusting the working directory, which is - // definitely not supported. Once that's fixed this hack should be able to - // be narrowed to only when there's an externally mapped name given back. - // // A potential plan to remove this is as follows - - // - Add API to determine if the name has been rewritten by the VFS. - // - Fix `clang-apply-replacements` to pass down the absolute path rather - // than changing the CWD. Narrow this hack down to just externally - // mapped paths. - // - Expose the requested filename. One possibility would be to allow - // redirection-FileEntryRefs to be returned, rather than returning - // the pointed-at-FileEntryRef, and customizing `getName()` to look - // through the indirection. // - Update callers such as `HeaderSearch::findUsableModuleForHeader()` - // to explicitly use the requested filename rather than just using + // to explicitly use the `getNameAsRequested()` rather than just using // `getName()`. // - Add a `FileManager::getExternalPath` API for explicitly getting the // remapped external filename when there is one available. Adopt it in @@ -341,9 +320,6 @@ FileManager::getFileRef(StringRef Filename, bool openFile, bool CacheFailure) { // Cache the redirection in the previously-inserted entry, still available // in the tentative return value. NamedFileEnt->second = FileEntryRef::MapValue(Redirection); - - // Fix the tentative return value. - NamedFileEnt = &Redirection; } FileEntryRef ReturnedRef(*NamedFileEnt); @@ -495,11 +471,11 @@ FileEntryRef FileManager::getVirtualFileRef(StringRef Filename, off_t Size, return FileEntryRef(NamedFileEnt); } -llvm::Optional<FileEntryRef> FileManager::getBypassFile(FileEntryRef VF) { +OptionalFileEntryRef FileManager::getBypassFile(FileEntryRef VF) { // Stat of the file and return nullptr if it doesn't exist. llvm::vfs::Status Status; if (getStatValue(VF.getName(), Status, /*isFile=*/true, /*F=*/nullptr)) - return None; + return std::nullopt; if (!SeenBypassFileEntries) SeenBypassFileEntries = std::make_unique< |