aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/FileManager.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-06-27[Basic] Use StringRef::drop_back (NFC) (#146195)Kazu Hirata1-1/+1
2025-05-31[Basic] Remove unused includes (NFC) (#142295)Kazu Hirata1-2/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-04-15[clang] Reject character devices in #embed for now (#135370)Mariya Podchishchaeva1-0/+2
See https://github.com/llvm/llvm-project/issues/126629 . Right now they are not supported properly and support requires modifying several layers of LLVM. For now simply reject them while proper support is being developed to avoid potential security problems.
2025-03-20[clang] Remove deprecated `FileManager` APIs (#132063)Jan Svoboda1-16/+0
This PR removes the `FileManager` APIs that have been deprecated for a while. LLVM 20.1.0 that was released earlier this month contains the formal deprecation of these APIs, so these should be fine to remove in the next major release.
2024-12-12[clang] Migrate away from PointerUnion::{is,get} (NFC) (#119724)Kazu Hirata1-4/+4
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null.
2024-12-11[clang] Migrate away from PointerUnion::{is,get} (NFC) (#119654)Kazu Hirata1-1/+1
Note that PointerUnion::{is,get} have been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with // isa<T>, cast<T> and the llvm::dyn_cast<T> I'm not touching PointerUnion::dyn_cast for now because it's a bit complicated; we could blindly migrate it to dyn_cast_if_present, but we should probably use dyn_cast when the operand is known to be non-null.
2024-10-21[SystemZ][z/OS] Add new openFileForReadBinary function, and pass IsText ↵Abhina Sree1-15/+19
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-09-20Revert "[SystemZ][z/OS] Propagate IsText parameter to open text files as ↵Abhina Sreeskantharajan1-6/+6
text (#107906)" This reverts commit edf3b277a5f2ebe144827ed47463c22743cac5f9.
2024-09-19[SystemZ][z/OS] Propagate IsText parameter to open text files as text (#107906)Abhina Sree1-6/+6
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-11[clang][deps] Print tracing VFS data (#108056)Jan Svoboda1-0/+11
Clang's `-cc1 -print-stats` shows lots of useful internal data including basic `FileManager` stats. Since this layer caches some results, it is unclear how that information translates to actual filesystem accesses. This PR uses `llvm::vfs::TracingFileSystem` to provide that missing information. Similar mechanism is implemented for `clang-scan-deps`'s verbose mode (`-v`). IO contention proved to be a real bottleneck a couple of times already and this new feature should make those easier to detect in the future. The tracing VFS is inserted below the caching FS and above the real FS.
2024-06-20Reland [clang][Sema, Lex, Parse] Preprocessor embed in C and C++ (#95802)Mariya Podchishchaeva1-1/+6
This commit implements the entirety of the now-accepted [N3017 -Preprocessor Embed](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm) and its sister C++ paper [p1967](https://wg21.link/p1967). It implements everything in the specification, and includes an implementation that drastically improves the time it takes to embed data in specific scenarios (the initialization of character type arrays). The mechanisms used to do this are used under the "as-if" rule, and in general when the system cannot detect it is initializing an array object in a variable declaration, will generate EmbedExpr AST node which will be expanded by AST consumers (CodeGen or constant expression evaluators) or expand embed directive as a comma expression. This reverts commit https://github.com/llvm/llvm-project/commit/682d461d5a231cee54d65910e6341769419a67d7. --------- Co-authored-by: The Phantom Derpstorm <phdofthehouse@gmail.com> Co-authored-by: Aaron Ballman <aaron@aaronballman.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com> Co-authored-by: H. Vetinari <h.vetinari@gmx.com>
2024-06-12Revert "✨ [Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C ↵Vitaly Buka1-6/+1
and Obj-C++ by-proxy)" (#95299) Reverts llvm/llvm-project#68620 Introduce or expose a memory leak and UB, see llvm/llvm-project#68620
2024-06-12[clang][Sema, Lex, Parse] Preprocessor embed in C and C++ (and Obj-C and ↵The Phantom Derpstorm1-1/+6
Obj-C++ by-proxy) (#68620) This commit implements the entirety of the now-accepted [N3017 - Preprocessor Embed](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3017.htm) and its sister C++ paper [p1967](https://wg21.link/p1967). It implements everything in the specification, and includes an implementation that drastically improves the time it takes to embed data in specific scenarios (the initialization of character type arrays). The mechanisms used to do this are used under the "as-if" rule, and in general when the system cannot detect it is initializing an array object in a variable declaration, will generate EmbedExpr AST node which will be expanded by AST consumers (CodeGen or constant expression evaluators) or expand embed directive as a comma expression. --------- Co-authored-by: Aaron Ballman <aaron@aaronballman.com> Co-authored-by: cor3ntin <corentinjabot@gmail.com> Co-authored-by: H. Vetinari <h.vetinari@gmx.com> Co-authored-by: Podchishchaeva, Mariya <mariya.podchishchaeva@intel.com>
2024-05-22[clang] Processing real directories added as virtual ones (#91645)Ivan Murashko1-15/+33
The `FileManager` might create a virtual directory that can be used later as a search path. This is the case when we use remapping, as demonstrated in the suggested LIT test. We might encounter a 'false cache miss' and add the same directory twice into `FileManager::SeenDirEntries` if the added record is a real directory that is present on a disk: - Once as a virtual directory - And once as a real one This isn't a problem if the added directories have the same name, as in this case, we will get a cache hit. However, it could lead to compilation errors if the directory names are different but point to the same folder. For example, one might use an absolute name and another a relative one. For instance, the **implicit-module-remap.cpp** LIT test will fail with the following message: ``` /.../implicit-module-remap.cpp.tmp/test.cpp:1:2: fatal error: module 'a' was built in directory '/.../implicit-module-remap.cpp.tmp' but now resides in directory '.' 1 | #include "a.h" | ^ 1 error generated. ``` The suggested fix checks if the added virtual directory is present on the disk and handles it as a real one if that is the case.
2024-04-25[clang-scan-deps] Fix contention when updating `TrackingStatistic`s in hot ↵Alexandre Ganea1-6/+8
code paths in `FileManager`. (#88427) `FileManager::getDirectoryRef()` and `FileManager::getFileRef()` are hot code paths in `clang-scan-deps`. These functions are updating on every call a few atomics related to printing statistics, which causes contention on high core count machines. ![Screenshot 2024-04-10 214123](https://github.com/llvm/llvm-project/assets/37383324/5756b1bc-cab5-4612-8769-ee7e03a66479) ![Screenshot 2024-04-10 214246](https://github.com/llvm/llvm-project/assets/37383324/3d560e89-61c7-4fb9-9330-f9e660e8fc8b) ![Screenshot 2024-04-10 214315](https://github.com/llvm/llvm-project/assets/37383324/006341fc-49d4-4720-a348-7af435c21b17) After this patch we make the variables local to the `FileManager`. In our test case, this saves about 49 sec over 1 min 47 sec of `clang-scan-deps` run time (1 min 47 sec before, 58 sec after). These figures are after applying my suggestion in https://github.com/llvm/llvm-project/pull/88152#issuecomment-2049803229, that is: ``` static bool shouldCacheStatFailures(StringRef Filename) { return true; } ``` Without the above, there's just too much OS noise from the high volume of `status()` calls with regular non-modules C++ code. Tested on Windows with clang-cl.
2024-02-14[clang][CodeGen] Shift relink option implementation away from module cloning ↵Jacob Lambert1-1/+1
(#81693) We recently implemented a new option allowing relinking of bitcode modules via the "-mllvm -relink-builtin-bitcode-postop" option. This implementation relied on llvm::CloneModule() in order to pass copies to modules and preserve the original modules for later relinking. However, cloning modules has been found to be prohibitively expensive, significantly increasing compilation time for large bitcode libraries. In this patch, we shift the relink option implementation to instead link the original modules initially, and reload modules from the file system if relinking is requested. This approach results in significantly reduced overhead. We accomplish this by creating a new ReloadModules() routine that can be called from a BackendConsumer class, to mimic the behavior of ASTConsumer's loadLinkModules(), but without access to the CompilerInstance. Because loading the bitcodes from the filesystem requires access to the FileManager class, we also forward a reference to the CompilerInstance class to the BackendConsumer. This mirrors what is already done for several CompilerInstance members, such as TargetOptions and CodeGenOptions. Finally, we needed to add a const specifier to the FileManager::getBufferForFile() routine to allow it to be called using the const reference returned from CompilerInstance::getFileManager()
2024-01-30[clang][DependencyScanner] Remove unused -ivfsoverlay files (#73734)Michael Spencer1-0/+7
`-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 Svoboda1-26/+0
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-20[clang] Use SmallString::operator std::string (NFC)Kazu Hirata1-1/+1
2023-09-28[clang][modules] Adopt `FileEntryRef` in the `HeaderFileInfo` block in PCM ↵Jan Svoboda1-15/+12
files (#67383) This patch adopts `FileEntryRef` in the `HeaderFileInfo`-writing part of `ASTWriter`. First, this patch removes the loop over `FileManager::VirtualFileEntries`. It's redundant, since all virtual file entries are also present in `SeenFileEntries` and thus already in `UIDToFiles`. Second, since we now no longer rely on `FileEntry::getLastRef()`/`FileEntry::getName()`, this patch takes care to establish which path gets used for each UID by picking the `FileEntryRef` with the most "`<`" name (instead of just relying on the `StringMap` iteration order). Note that which `FileEntry`/`FileEntryRef` objects we pick for each UID for serialization into the `llvm::OnDiskChainedHashTable` doesn't really matter. The hash function only includes the file size and modification time. The file name only plays role during resolution of hash collisions, in which case it goes through `FileManager` and resolves to a `FileEntry` that gets pointer-compared with the queried `FileEntry`. (Reincarnation of [D143414](https://reviews.llvm.org/D143414) and [D142780](https://reviews.llvm.org/D142780).)
2023-09-13[clang] NFCI: Use `FileEntryRef` in `FileManager::getCanonicalName()`Jan Svoboda1-2/+2
2023-09-13[clang] NFCI: Use `FileEntryRef` in `FileManager::getBufferForFile()`Jan Svoboda1-2/+3
2023-08-01[lit][clang] Avoid realpath on Windows due to MAX_PATH limitationsSaleem Abdulrasool1-20/+35
Running lit tests on Windows can fail because its use of `os.path.realpath` expands substitute drives, which are used to keep paths short and avoid hitting MAX_PATH limitations. Changes lit logic to: Use `os.path.abspath` on Windows, where `MAX_PATH` is a concern that we can work around using substitute drives, which `os.path.realpath` would resolve. Use `os.path.realpath` on Unix, where the current directory always has symlinks resolved, so it is impossible to preserve symlinks in the presence of relative paths, and so we must make sure that all code paths use real paths. Also updates clang's `FileManager::getCanonicalName` and `ExtractAPI` code to avoid resolving substitute drives (i.e. resolving to a path under a different root). How tested: built with `-DLLVM_ENABLE_PROJECTS=clang` and built `check-all` on both Windows Differential Revision: https://reviews.llvm.org/D154130 Reviewed By: @benlangmuir Patch by Tristan Labelle <tristan@thebrowser.company>!
2023-06-15[clang] NFC: Use `DirectoryEntryRef` in `FileManager::getCanonicalName()`Jan Svoboda1-5/+4
This patch removes the last use of deprecated `DirectoryEntry::getName()`. Depends on D151855. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D151922
2023-05-25[clang] Make `FileEntryRef::getDir()` return the as-requested ↵Jan Svoboda1-1/+1
`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
2023-02-07[clang] NFC: Remove GCC 5.1 workaround in FileEntryJan Svoboda1-2/+1
We no longer support GCC 5.1 (D122976), so let's remove the workaround in FileEntry. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D143427
2022-12-20[Clang] Prepare for llvm::Optional becoming std::optional.Benjamin Kramer1-1/+1
The needed tweaks are mostly trivial, the one nasty bit is Clang's usage of OptionalStorage. To keep this working old Optional stays around as clang::CustomizableOptional, with the default Storage removed. Optional<File/DirectoryEntryRef> is replaced with a typedef. I tested this with GCC 7.5, the oldest supported GCC I had around. Differential Revision: https://reviews.llvm.org/D140332
2022-12-18Revert "[clang] Convert OptionalFileEntryRefDegradesToFileEntryPtr to ↵Krzysztof Parzyszek1-1/+1
std::optional" This reverts commit 8f0df9f3bbc6d7f3d5cbfd955c5ee4404c53a75d. The Optional*RefDegradesTo*EntryPtr types want to keep the same size as the underlying type, which std::optional doesn't guarantee. For use with llvm::Optional, they define their own storage class, and there is no way to do that in std::optional. On top of that, that commit broke builds with older GCCs, where std::optional was not trivially copyable (static_assert in the clang sources was failing).
2022-12-17[clang] Convert OptionalFileEntryRefDegradesToFileEntryPtr to std::optionalKrzysztof Parzyszek1-1/+1
2022-12-09[Basic] Use std::optional in FileManager.cpp (NFC)Kazu Hirata1-1/+2
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-03[Basic] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+1
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-08-05[clang] Fix redirection behaviour for cached FileEntryRefBen Langmuir1-7/+1
In 6a79e2ff1989b we changed Filemanager::getEntryRef() to return the redirecting FileEntryRef instead of looking through the redirection. This commit fixes the case when looking up a cached file path to also return the redirecting FileEntryRef. This mainly affects the behaviour of calling getNameAsRequested() on the resulting entry ref. Differential Revision: https://reviews.llvm.org/D131273
2022-08-03[clang] Add FileEntryRef::getNameAsRequested()Ben Langmuir1-8/+1
As progress towards having FileManager::getFileRef() return the path as-requested by default, return a FileEntryRef that can use getNameAsRequested() to retrieve this path, with the ultimate goal that this should be the behaviour of getName() and clients should explicitly request the "external" name if they need to (see comment in FileManager::getFileRef). For now, getName() continues to return the external path by looking through the redirects. For now, the new function is only used in unit tests. Differential Revision: https://reviews.llvm.org/D131004
2022-08-01[clang] Only modify FileEntryRef names that are externally remappedBen Langmuir1-14/+2
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
2022-04-11[VFS] RedirectingFileSystem only replace path if not already mappedBen Barham1-11/+50
If the `ExternalFS` has already remapped to an external path then `RedirectingFileSystem` should not change it to the originally provided path. This fixes the original path always being used if multiple VFS overlays were provided and the path wasn't found in the highest (ie. first in the chain). For now this is accomplished through the use of a new `ExposesExternalVFSPath` field on `vfs::Status`. This flag is true when the `Status` has an external path that's different from its virtual path, ie. the contained path is the external path. See the plan in `FileManager::getFileRef` for where this is going - eventually we won't need `IsVFSMapped` any more and all returned paths should be virtual. Resolves rdar://90578880 and llvm-project#53306. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D123398
2022-04-07Remove a few effectively-unused FileEntry APIs. NFCSam McCall1-3/+0
- isValid: FileManager only ever returns valid FileEntries (see next point) - construction from outside FileManager (both FileEntry and DirectoryEntry). It's not possible to create a useful FileEntry this way, there are no setters. This was only used in FileEntryTest, added a friend to enable this. A real constructor is cleaner but requires larger changes to FileManager. Differential Revision: https://reviews.llvm.org/D123197
2022-04-05Revert "[VFS] RedirectingFileSystem only replace path if not already mapped"Ben Barham1-20/+12
This reverts commit 3fda0edc51fd68192a30e302d45db081bb02d7f9, which breaks crash reproducers in very specific circumstances. Specifically, since crash reproducers have `UseExternalNames` set to false, the `File->getFileEntry().getDir()->getName()` call in `DoFrameworkLookup` would use the *cached* directory name instead of the directory of the looked-up file. The plan is to re-commit this patch but to *add* `ExposesExternalVFSPath` rather than replace `IsVFSMapped`. Differential Revision: https://reviews.llvm.org/D123103
2022-04-05FileManager: std::map => BumpPtrAllocator + DenseMap of pointers. NFCSam McCall1-62/+69
This is both smaller and faster. Differential Revision: https://reviews.llvm.org/D123144
2022-03-30[VFS] RedirectingFileSystem only replace path if not already mappedBen Barham1-12/+20
If the `ExternalFS` has already remapped a path then the `RedirectingFileSystem` should not change it to the originally provided path. This fixes the original path always being used if multiple VFS overlays were provided and the path wasn't found in the highest (ie. first in the chain). This also renames `IsVFSMapped` to `ExposesExternalVFSPath` and only sets it if `UseExternalName` is true. This flag then represents that the `Status` has an external path that's different from its virtual path. Right now the contained path is still the external path, but further PRs will change this to *always* be the virtual path. Clients that need the external can then request it specifically. Note that even though `ExposesExternalVFSPath` isn't set for all VFS-mapped paths, `IsVFSMapped` was only being used by a hack in `FileManager` that was specific to module searching. In that case `UseExternalNames` is always `true` and so that hack still applies. Resolves rdar://90578880 and llvm-project#53306. Differential Revision: https://reviews.llvm.org/D122549
2021-10-29Fix a use-after-scope from 99023627010bbfefb71e25a2b4d056de1cbd354eDuncan P. N. Exon Smith1-2/+2
2021-10-29Support: Use sys::path::is_style_{posix,windows}() in a few placesDuncan P. N. Exon Smith1-9/+9
Use the new sys::path::is_style_posix() and is_style_windows() in a few places that need to detect the system's native path style. In llvm/lib/Support/Path.cpp, this patch removes most uses of the private `real_style()`, where is_style_posix() and is_style_windows() are just a little tidier. Elsewhere, this removes `_WIN32` macro checks. Added a FIXME to a FileManagerTest that seemed fishy, but maintained the existing behaviour. Differential Revision: https://reviews.llvm.org/D112289
2021-09-01VFS: Document goals of 'use-external-name' and related logic, NFCDuncan P. N. Exon Smith1-0/+12
Document 'use-external-name' and the various bits of logic that make it work, to avoid others having to repeat the archival work (given that I added getFileRefReturnsCorrectNameForDifferentStatPath to FileManagerTest, seems possible I understood this once before!). - b59cf679e81483cbb3a9252056b7528f4c49586c added 'use-external-name' to RedirectingFileSystem. This causes `stat`s to return the external name for a redirected file instead of the name it was accessed by, leaking it through the VFS. - d066d4c849be06a01c0d17e8dc206913f4e7bfe3 propagated the external name further through clang::FileManager. - 4dc5573acc0d2e7c59d8bac2543eb25cb4b32984, which added clang::FileEntryRef to clang::FileManager, has complicated concession to account for this as well (since refactored a bit). The goal of 'use-external-name' is to enable Clang to report "real" file paths to users (via diagnostics) and to external tools (such as debuggers reading debug info and build systems reading `.d` files). I've added FIXMEs to look at other channels for communicating the external names, since the current implementation adds complexity to FileManager and exposes an inconsistent interface to clients. Besides that, the FileManager logic appears to be kicking in outside of 'use-external-name'. Seems that *some* vfs::FileSystem implementations canonicalize some paths returned by `stat` in *some* cases (the bug isn't fully understood yet). Volodymyr Sapsai is investigating, this at least better documents what *is* understood.
2021-07-08PR51018: Remove explicit conversions from SmallString to StringRef to ↵David Blaikie1-2/+2
future-proof against C++23 C++23 will make these conversions ambiguous - so fix them to make the codebase forward-compatible with C++23 (& a follow-up change I've made will make this ambiguous/invalid even in <C++23 so we don't regress this & it generally improves the code anyway)
2021-06-25[clang] Rename StringRef _lower() method calls to _insensitive()Martin Storsjö1-1/+1
This is mostly a mechanical change, but a testcase that contains parts of the StringRef class (clang/test/Analysis/llvm-conventions.cpp) isn't touched.
2021-04-14[clang][FileManager] Support empty file name in getVirtualFileRef for ↵Alex Lorenz1-3/+6
serialized diagnostics After https://reviews.llvm.org/D90484 libclang is unable to read a serialized diagnostic file which contains a diagnostic which came from a file with an empty filename. The reason being is that the serialized diagnostic reader is creating a virtual file for the "" filename, which now fails after the changes in https://reviews.llvm.org/D90484. This patch restores the previous behavior in getVirtualFileRef by allowing it to construct a file entry ref with an empty name by pretending its name is "." so that the directory entry can be created. Differential Revision: https://reviews.llvm.org/D100428
2020-12-23Basic: Add native support for stdin to SourceManager and FileManagerDuncan P. N. Exon Smith1-0/+23
Add support for stdin to SourceManager and FileManager. Adds FileManager::getSTDIN, which adds a FileEntryRef for `<stdin>` and reads the MemoryBuffer, which is stored as `FileEntry::Content`. Eventually the other buffers in `ContentCache` will sink to here as well -- we probably usually want to load/save a MemoryBuffer eagerly -- but it's happening early for stdin to get rid of CompilerInstance::InitializeSourceManager's final call to `SourceManager::overrideFileContents`. clang/test/CXX/modules-ts/dcl.dcl/dcl.module/dcl.module.export/p1.cpp relies on building a module from stdin; supporting that requires setting ContentCache::BufferOverridden. Differential Revision: https://reviews.llvm.org/D93148
2020-12-23Basic: Support named pipes natively in SourceManager and FileManagerDuncan P. N. Exon Smith1-1/+1
Handle named pipes natively in SourceManager and FileManager, removing a call to `SourceManager::overrideFileContents` in `CompilerInstance::InitializeSourceManager` (removing a blocker for sinking the content cache to FileManager (which will incidently sink this new named pipe logic with it)). SourceManager usually checks if the file entry's size matches the eventually loaded buffer, but that's now skipped for named pipes since the `stat` won't reflect the full size. Since we can't trust `ContentsEntry->getSize()`, we also need shift the check for files that are too large until after the buffer is loaded... and load the buffer immediately in `createFileID` so that no client gets a bad value from `ContentCache::getSize`. `FileManager::getBufferForFile` also needs to treat these files as volatile when loading the buffer. Native support in SourceManager / FileManager means that named pipes can also be `#include`d, and clang/test/Misc/dev-fd-fs.c was expanded to check for that. This is a new version of 3b18a594c7717a328c33b9c1eba675e9f4bd367c, which was reverted in b34632201987eed369bb7ef4646f341b901c95b8 since it was missing the `SourceManager` changes. Differential Revision: https://reviews.llvm.org/D92531
2020-12-02Revert "Frontend: Sink named pipe logic from CompilerInstance down to ↵Duncan P. N. Exon Smith1-1/+1
FileManager" This reverts commit 3b18a594c7717a328c33b9c1eba675e9f4bd367c, since apparently this doesn't work everywhere. E.g., clang-x86_64-debian-fast/3889 (http://lab.llvm.org:8011/#/builders/109/builds/3889) gives me: ``` + : 'RUN: at line 8' + /b/1/clang-x86_64-debian-fast/llvm.obj/bin/clang -x c /dev/fd/0 -E + cat /b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Misc/dev-fd-fs.c fatal error: file '/dev/fd/0' modified since it was first processed 1 error generated. ```
2020-12-02Frontend: Sink named pipe logic from CompilerInstance down to FileManagerDuncan P. N. Exon Smith1-1/+1
Remove compilicated logic from CompilerInstance::InitializeSourceManager to deal with named pipes, updating FileManager::getBufferForFile to handle it in a more straightforward way. The existing test at clang/test/Misc/dev-fd-fs.c covers the new behaviour (just like it did the old behaviour). Differential Revision: https://reviews.llvm.org/D90733
2020-11-30FileManager: Add FileEntryRef::getDir, returning DirectoryEntryRefDuncan P. N. Exon Smith1-19/+23
Add `FileEntryRef::getDir`, which returns a `DirectoryEntryRef`. This includes a few changes: - Customize `OptionalStorage` so that `Optional<DirectoryEntryRef>` is pointer-sized (like the change made to `Optional<FileEntryRef>`). Factored out a common class, `FileMgr::MapEntryOptionalStorage`, to reduce the code duplication. - Store an `Optional<DirectoryEntryRef>` in `FileEntryRef::MapValue`. This is set if and only if `MapValue` has a real `FileEntry`. - Change `FileManager::getFileRef` and `getVirtualFileRef` to use `getDirectoryRef` and store it in the `StringMap` for `FileEntryRef`. Differential Revision: https://reviews.llvm.org/D90484