From 98cf745a032ea0d29fbddaa204760d4e823c237f Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Mon, 1 Aug 2022 13:30:41 -0700 Subject: [clang] Only modify FileEntryRef names that are externally remapped As progress towards having FileEntryRef contain the requested name of the file, this commit narrows the "remap" hack to only apply to paths that were remapped to an external contents path by a VFS. That was always the original intent of this code, and the fact it was making relative paths absolute was an unintended side effect. Differential Revision: https://reviews.llvm.org/D130935 --- clang/lib/Basic/FileManager.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'clang/lib/Basic/FileManager.cpp') diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index b66780a..451c7c3 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -274,8 +274,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,19 +292,7 @@ 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 -- cgit v1.1