From bdc3ce9e8f8dda42ed286f72094fbbdf0347cbfa Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Thu, 25 May 2023 09:22:38 -0700 Subject: [clang] Make `FileEntryRef::getDir()` return the as-requested `DirectoryEntryRef` For redirected file entries, `FileEntryRef::getDir()` returns the parent directory entry of the target file entry. This differs from `FileEntry::getDir()` that always returns the parent directory that was last used to look up that file. After switching from `FileEntry` to `FileEntryRef` for umbrella headers in D142113, this discrepancy became observable and caused Clang to emit incorrect diagnostics. This patch changes Clang so that it always associates `FileEntryRef` with the parent directory that was used to look it up. This brings its behavior closer to `FileEntry`, but without the hacky mutation. This also ensures that `llvm::sys::path::parent_path(FileRef->getNameAsRequested()) == FileRef->getDir()->getName()`. Previously, `FileRef->getDir()` would fall underneath the redirecting VFS into the world of on-disk paths. Reviewed By: benlangmuir, rmaz Differential Revision: https://reviews.llvm.org/D151398 --- clang/lib/Basic/FileManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'clang/lib/Basic/FileManager.cpp') diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 7d6fc47..0f544f0 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -319,7 +319,7 @@ 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); + NamedFileEnt->second = FileEntryRef::MapValue(Redirection, DirInfo); } FileEntryRef ReturnedRef(*NamedFileEnt); -- cgit v1.1