diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2023-05-25 09:22:38 -0700 |
---|---|---|
committer | Jan Svoboda <jan_svoboda@apple.com> | 2023-05-25 12:36:57 -0700 |
commit | bdc3ce9e8f8dda42ed286f72094fbbdf0347cbfa (patch) | |
tree | 8281b4b4734a104889f041d0d4b119fb868c7279 /clang/unittests/Basic/FileManagerTest.cpp | |
parent | 9762854538a256d0de38bd413e6d0c29fd2af4f7 (diff) | |
download | llvm-bdc3ce9e8f8dda42ed286f72094fbbdf0347cbfa.zip llvm-bdc3ce9e8f8dda42ed286f72094fbbdf0347cbfa.tar.gz llvm-bdc3ce9e8f8dda42ed286f72094fbbdf0347cbfa.tar.bz2 |
[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
Diffstat (limited to 'clang/unittests/Basic/FileManagerTest.cpp')
-rw-r--r-- | clang/unittests/Basic/FileManagerTest.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp index 146a609..4c8205b 100644 --- a/clang/unittests/Basic/FileManagerTest.cpp +++ b/clang/unittests/Basic/FileManagerTest.cpp @@ -310,6 +310,26 @@ TEST_F(FileManagerTest, getFileRefReturnsCorrectNameForDifferentStatPath) { EXPECT_EQ(&F2->getFileEntry(), &F2Alias2->getFileEntry()); } +TEST_F(FileManagerTest, getFileRefReturnsCorrectDirNameForDifferentStatPath) { + // Inject files with the same inode into distinct directories (name & inode). + auto StatCache = std::make_unique<FakeStatCache>(); + StatCache->InjectDirectory("dir1", 40); + StatCache->InjectDirectory("dir2", 41); + StatCache->InjectFile("dir1/f.cpp", 42); + StatCache->InjectFile("dir2/f.cpp", 42, "dir1/f.cpp"); + + manager.setStatCache(std::move(StatCache)); + auto Dir1F = manager.getFileRef("dir1/f.cpp"); + auto Dir2F = manager.getFileRef("dir2/f.cpp"); + + ASSERT_FALSE(!Dir1F); + ASSERT_FALSE(!Dir2F); + EXPECT_EQ("dir1", Dir1F->getDir().getName()); + EXPECT_EQ("dir2", Dir2F->getDir().getName()); + EXPECT_EQ("dir1/f.cpp", Dir1F->getNameAsRequested()); + EXPECT_EQ("dir2/f.cpp", Dir2F->getNameAsRequested()); +} + // getFile() returns the same FileEntry for virtual files that have // corresponding real files that are aliases. TEST_F(FileManagerTest, getFileReturnsSameFileEntryForAliasedVirtualFiles) { |