summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/VirtualFileSystem.cpp
AgeCommit message (Collapse)Author
2025-01-19[Support] Avoid repeated hash lookups (NFC) (#123503)Kazu Hirata
2024-11-20[Support] Remove unused includes (NFC) (#116752)Kazu Hirata
Identified with misc-include-cleaner.
2024-10-21[SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText ↵Abhina Sree
parameter to getBufferForFile (#111723) This patch adds an IsText parameter to the following getBufferForFile, getBufferForFileImpl. We introduce a new virtual function openFileForReadBinary which defaults to openFileForRead except in RealFileSystem which uses the OF_None flag instead of OF_Text. The default is set to OF_Text instead of OF_None, this change in value does not affect any other platforms other than z/OS. Setting this parameter correctly is required to open files on z/OS in the correct encoding. The IsText parameter is based on the context of where we open files, for example, in the ASTReader, HeaderMap requires that files always be opened in binary even though they might be tagged as text.
2024-10-20[Support] Use a hetrogenous lookup with std::map (NFC) (#113075)Kazu Hirata
2024-09-20Revert "[SystemZ][z/OS] Propagate IsText parameter to open text files as ↵Abhina Sreeskantharajan
text (#107906)" This reverts commit edf3b277a5f2ebe144827ed47463c22743cac5f9.
2024-09-19[SystemZ][z/OS] Propagate IsText parameter to open text files as text (#107906)Abhina Sree
This patch adds an IsText parameter to the following functions openFileForRead, getBufferForFile, getBufferForFileImpl and determines whether a file is text by querying the file tag on z/OS. The default is set to OF_Text instead of OF_None, this change in value does not affect any other platforms other than z/OS.
2024-09-06[llvm][support] Implement tracing virtual file system (#88326)Jan Svoboda
LLVM-based tools often use the `llvm::vfs::FileSystem` instrastructure to access the file system. This patch adds new kind of a VFS that performs lightweight tracing of file system operations on an underlying VFS. This is supposed to aid in investigating file system traffic without resorting to instrumentation on the operating system level. There will be follow-up patches that integrate this into Clang and its dependency scanner.
2024-08-25[llvm] Prefer StringRef::substr to StringRef::slice (NFC) (#105943)Kazu Hirata
S.substr(N) is simpler than S.slice(N, StringRef::npos) and S.slice(N, S.size()). Also, substr is probably better recognizable than slice thanks to std::string_view::substr.
2024-08-04[llvm] Construct SmallVector with ArrayRef (NFC) (#101872)Kazu Hirata
2024-06-21[VFS] Avoid <stack> include (NFC)Nikita Popov
Directly use a vector instead of wrapping it in a stack, like we do in most places.
2024-06-13[llvm-project] Fix typo "seperate" (#95373)Jay Foad
2024-06-06[clang] Fix handling of adding a file with the same name as an existing dir ↵jensmassberg
to VFS (#94461) When trying to add a file to clang's VFS via `addFile` and a directory of the same name already exists, we run into a [out-of-bound access](https://github.com/llvm/llvm-project/blob/145815c180fc82c5a55bf568d01d98d250490a55/llvm/lib/Support/Path.cpp#L244). The problem is that the file name is [recognised as existing path]( https://github.com/llvm/llvm-project/blob/145815c180fc82c5a55bf568d01d98d250490a55/llvm/lib/Support/VirtualFileSystem.cpp#L896) and thus continues to process the next part of the path which doesn't exist. This patch adds a check if we have reached the last part of the filename and return false in that case. This we reject to add a file if a directory of the same name already exists. This is in sync with [this check](https://github.com/llvm/llvm-project/blob/145815c180fc82c5a55bf568d01d98d250490a55/llvm/lib/Support/VirtualFileSystem.cpp#L903) that rejects adding a path if a file of the same name already exists.
2024-05-08[llvm] Use StringRef::operator== instead of StringRef::equals (NFC) (#91441)Kazu Hirata
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator==/!= outnumber StringRef::equals by a factor of 70 under llvm/ in terms of their usage. - The elimination of StringRef::equals brings StringRef closer to std::string_view, which has operator== but not equals. - S == "foo" is more readable than S.equals("foo"), especially for !Long.Expression.equals("str") vs Long.Expression != "str".
2024-05-07[modules] Accept equivalent module caches from different symlink (#90925)Ellis Hoag
Use `VFS.equivalent()`, which follows symlinks, to check if two module cache paths are equivalent. This prevents a PCH error when building from a different path that is a symlink of the original. ``` error: PCH was compiled with module cache path '/home/foo/blah/ModuleCache/2IBP1TNT8OR8D', but the path is currently '/data/users/foo/blah/ModuleCache/2IBP1TNT8OR8D' 1 error generated. ```
2024-05-04[Support] Use StringRef::operator== instead of StringRef::equals (NFC) (#91042)Kazu Hirata
I'm planning to remove StringRef::equals in favor of StringRef::operator==. - StringRef::operator== outnumbers StringRef::equals by a factor of 25 under llvm/ in terms of their usage. - The elimination of StringRef::equals brings StringRef closer to std::string_view, which has operator== but not equals. - S == "foo" is more readable than S.equals("foo"), especially for !Long.Expression.equals("str") vs Long.Expression != "str".
2024-04-12[llvm][vfs] Make vfs::FileSystem::exists() virtual NFC (#88575)Artem Chikin
Allow a `vfs::FileSystem` to provide a more efficient implementation of `exists()` if they are able to. The existing `FileSystem` implementations continue to default to using `status()` except that overlay, proxy, and redirecting filesystems are taught to forward calls to `exists()` correctly to their wrapped/external filesystem. Co-authored-by: Ben Langmuir <blangmuir@apple.com>
2024-04-12[llvm][vfs] NFCI: Remove `const` from `VFS::getRealPath()`Jan Svoboda
This is an NFC change split from https://github.com/llvm/llvm-project/pull/68645.
2024-03-15[llvm][vfs] Preserve paths for fallback/fallthrough in RedirectingFileSystem ↵Ben Langmuir
(#85307) When we lookup in the external filesystem, do not remove . and .. components from the original path. For .. this is a correctness issue in the presence of symlinks, while for . it is simply better practice to preserve the original path to better match the behaviour of other filesystems. The only modification we need is to apply the working directory, since it could differ from the external filesystem. rdar://123655660
2024-02-03[Support] Use StringRef::starts_with (NFC)Kazu Hirata
2024-01-30[clang][DependencyScanner] Remove unused -ivfsoverlay files (#73734)Michael Spencer
`-ivfsoverlay` files are unused when building most modules. Enable removing them by, * adding a way to visit the filesystem tree with extensible RTTI to access each `RedirectingFileSystem`. * Adding tracking to `RedirectingFileSystem` to record when it actually redirects a file access. * Storing this information in each PCM. Usage tracking is only enabled when iterating over the source manager and affecting modulemaps. Here each path is stated to cause an access. During scanning these stats all hit the cache.
2024-01-24[clang] NFC: Remove `{File,Directory}Entry::getName()` (#74910)Jan Svoboda
The files and directories that Clang accesses are uniqued by their inode. For each inode `FileManager` will create exactly one `FileEntry` or `DirectoryEntry` object, which makes answering the question _"Are these two files/directories the same?"_ a simple pointer equality check. However, since the same inode can be accessed through multiple different paths, asking the `FileEntry` or `DirectoryEntry` object _"What is your name?"_ doesn't have clear semantics. In c0ff9908 we started reporting the most recent name used to access the entry, which turned out to be necessary for Clang modules. However, the long-term solution has always been to explicitly track the as-requested name. This has been implemented in 4dc5573a as `FileEntryRef` and `DirectoryEntryRef`. The `DirectoryEntry::getName()` interface has been deprecated since the Clang 17 release and `FileEntry::getName()` since Clang 18. We have replaced uses of these deprecated APIs in `main` with `DirectoryEntryRef::getName()` and `FileEntryRef::getName()` respectively. This makes it possible to remove `{File,Directory}Entry::getName()` for good along with the `FileManager` code that implements them.
2024-01-17[Support] Use SmallString::operator std::string (NFC)Kazu Hirata
2023-11-03[Support] Use StringRef::starts_with/ends_with instead of ↵Simon Pilgrim
startswith/endswith. NFC. startswith/endswith wrap starts_with/ends_with and will eventually go away (to more closely match string_view)
2023-09-27[NFC] Use const references to avoid copying objects in for-loopsGregory Alfonso
Differential Revision: https://reviews.llvm.org/D139487
2023-08-30[NFC] Remove unused variables declared in conditionsTakuya Shimizu
D152495 makes clang warn on unused variables that are declared in conditions like `if (int var = init) {}` This patch is an NFC fix to suppress the new warning in llvm,clang,lld builds to pass CI in the above patch. Differential Revision: https://reviews.llvm.org/D158016
2023-08-15Revert "Reland "[Clang][SemaCXX] Add unused warning for variables declared ↵Takuya Shimizu
in condition expressions"" This causes a lot of warning in sanitizer build: https://lab.llvm.org/buildbot/#/builders/258/builds/5424 https://lab.llvm.org/buildbot/#/builders/36/builds/36560 This reverts commit 8e329caa944c377c51ef567d5aa67cfac9ffd0fa.
2023-08-15Reland "[Clang][SemaCXX] Add unused warning for variables declared in ↵Takuya Shimizu
condition expressions" This patch marks the declarations with initializations in condition expressions such as if (int var = init) as unreferenced so that -Wunused can warn on them. Fixes https://github.com/llvm/llvm-project/issues/61681 Reviewed By: cor3ntin Differential Revision: https://reviews.llvm.org/D152495
2023-07-22[VirtualFileSystem] Use std::map::emplaceFangrui Song
2023-07-21[VirtualFileSystem] Make gcc<7.5 happy after ↵Fangrui Song
75d71800aa384ee58663d892c325572f5588df2a There is a libstdc++ stl_map.h bug that is only back ported to 7.5. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78595#c13 ``` /tmp/opt/gcc-7.3.0/include/c++/7.3.0/bits/stl_tree.h:2091:28: error: no matching function for call to ‘std::_Rb_tree<std::__cxx11::basic_string<char>, std::pair<const std::__cxx11::basic_string<char>, std::unique_ptr<llvm::vfs::detail::InMemoryNode> >, std::_Select1st<std::pair<const std::__cxx11::basic_string<char>, std::unique_ptr<llvm::vfs::detail::InMemoryNode> > >, std::less<std::__cxx11::basic_string<char> >, std::allocator<std::pair<const std::__cxx11::basic_string<char>, std::unique_ptr<llvm::vfs::detail::InMemoryNode> > > >::_M_get_insert_unique_pos(std::pair<llvm::StringRef, std::unique_ptr<llvm::vfs::detail::InMemoryNode> >::first_type&)’ = _M_get_insert_unique_pos(_KeyOfValue()(__v)); ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~ ``` Just construct a std::string from StringRef to work around it.
2023-07-19[VirtualFileSystem] Use map to stabilize iteration orderFangrui Song
StringMap iteration order is not guaranteed to be deterministic (https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h). Tested by `TEST_F(InMemoryFileSystemTest, DirectoryIteration)`.
2023-07-10[llvm][vfs] For virtual directories, use the virtual path as the real pathJan Svoboda
A follow-up to D135841. This patch returns the virtual path for directories from `RedirectingFileSystem`. This ensures the contents of `Path` are the same as the contents of `FS->getRealPath(Path)`. This also means we can drop the workaround in Clang's module map canonicalization, where we couldn't use the real path for a directory if it resolved to a different `DirectoryEntry`. In addition to that, we can also avoid introducing new workaround for a bug triggered by the newly introduced test case. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D135849
2023-05-02[llvm][vfs] Avoid silent fallback to process-wide working directoryBen Langmuir
In createPhysicalFileSystem, preserve the per-instance working directory, even after the first call to getcwd fails. rdar://108213753 Differential Revision: https://reviews.llvm.org/D149173
2023-01-14[llvm] Include <optional> instead of "llvm/ADT/Optional.h" (NFC)Kazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-20[llvm] Use std::optional instead of OptionalKazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-16std::optional::value => operator*/operator->Fangrui Song
value() has undesired exception checking semantics and calls __throw_bad_optional_access in libc++. Moreover, the API is unavailable without _LIBCPP_NO_EXCEPTIONS on older Mach-O platforms (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). This commit fixes LLVMAnalysis and its dependencies.
2022-12-16[vfs] Allow root paths relative to the vfsoverlay YAML fileHaowei Wu
This change adds 'root-relative' option in vfsoverlay YAML file format so the root patchs can be relative to the YAML file directory instead of the current working directory. Differential Revision: https://reviews.llvm.org/D137473
2022-12-16[Support] llvm::Optional => std::optionalFangrui Song
https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-10Don't include None.h (NFC)Kazu Hirata
I've converted all known uses of None to std::nullopt, so we no longer need to include None.h. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-08[llvm] Call reserve before push_back in a loopGregory Alfonso
It is generally good practice, if you know how big the vector is going to be in the end, to reserve before continually calling "push_back" or "emplace_back" Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D139483
2022-12-02[llvm] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-25[Support] Use std::optional in VirtualFileSystem.cpp (NFC)Kazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-08-08[llvm] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song
With C++17 there is no Clang pedantic warning or MSVC C5051.
2022-07-13[llvm] Use value instead of getValue (NFC)Kazu Hirata
2022-06-25[llvm] Don't use Optional::hasValue (NFC)Kazu Hirata
This patch replaces Optional::hasValue with the implicit cast to bool in conditionals only.
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata
2022-06-21[llvm][vfs] Implement in-memory symlinksJan Svoboda
This patch implements symlinks for the in-memory VFS. Original author: @erik.pilkington. Depends on D117648 & D117649. Reviewed By: sammccall Differential Revision: https://reviews.llvm.org/D117650
2022-06-21[llvm][vfs] NFC: Promote `InMemoryDirIterator` to nested classJan Svoboda
2022-06-21[llvm][vfs] NFC: Promote `lookupInMemoryNode()` to member functionJan Svoboda
2022-06-21[llvm][vfs] NFC: Rename `InMemoryFileSystem::addHardLink()` argumentsJan Svoboda