summaryrefslogtreecommitdiff
path: root/clang/lib/Lex/HeaderMap.cpp
AgeCommit message (Collapse)Author
2025-06-15[clang] Remove unused includes (NFC) (#144285)Kazu Hirata
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-05-29[SystemZ][z/OS] Add back include required for strnlen functionAbhina Sreeskantharajan
2025-05-26[Lex] Remove unused includes (NFC) (#141523)Kazu Hirata
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-03-20[Lex][Clang] Add checking to HeaderMapImpl::getString to make it more robust ↵Shafik Yaghmour
(#131677) Static analysis identified the Len - 1 expression in HeaderMapImpl::getString as problematic if Len is zero. After filing this issue: https://github.com/llvm/llvm-project/issues/130185 Indeed we should be checking MaxLen and verify it is not zero as well. Fixes: https://github.com/llvm/llvm-project/issues/130185
2024-11-16[Lex] Remove unused includes (NFC) (#116460)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.
2023-12-13[SystemZ][z/OS] Add missing strnlen function for z/OS to fix build failures ↵Abhina Sree
(#75339) This patch adds strnlen to the zOSSupport.h file to fix build failures in multiple files.
2023-09-23[Lex] Use llvm::byteswap instead of sys::getSwappedBytes (NFC)Kazu Hirata
2023-09-13[clang] NFCI: Use `FileEntryRef` in `FileManager::getBufferForFile()`Jan Svoboda
2023-01-28Use llvm::byteswap instead of ByteSwap_{16,32,64} (NFC)Kazu Hirata
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.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
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with 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-12-03[clang] 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
2021-10-12[clang][lex] Remark on search path usageJan Svoboda
For dependency scanning, it would be useful to collect header search paths (provided on command-line via `-I` and friends) that were actually used during preprocessing. This patch adds that feature to `HeaderSearch` along with a new remark that reports such paths as they get used. Previous version of this patch tried to use the existing `LookupFileCache` to report used paths via `HitIdx`. That doesn't work for `ComputeUserEntryUsage` (which is intended to be called *after* preprocessing), because it indexes used search paths by the file name. This means the values get overwritten when the code contains `#include_next`. Note that `HeaderSearch` doesn't use `HeaderSearchOptions::UserEntries` directly. Instead, `InitHeaderSearch` pre-processes them (adds platform-specific paths, removes duplicates, removes paths that don't exist) and creates `DirectoryLookup` instances. This means we need a mechanism for translating between those two. It's not possible to go from `DirectoryLookup` back to the original `HeaderSearch`, so `InitHeaderSearch` now tracks the relationships explicitly. Depends on D111557. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D102923
2021-06-25[clang] Rename StringRef _lower() method calls to _insensitive()Martin Storsjö
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-06-03[clang][clangd] Use reverse header map lookup in suggestPathToFileForDiagnosticsDmitry Polukhin
Summary: suggestPathToFileForDiagnostics is actively used in clangd for converting an absolute path to a header file to a header name as it should be spelled in the sources. Current approach converts absolute path to relative path. This diff implements missing logic that makes a reverse lookup from the relative path to the key in the header map that should be used in the sources. Prerequisite diff: https://reviews.llvm.org/D103229 Test Plan: check-clang Reviewers: dexonsmith, bruno, rsmith Subscribers: cfe-commits Tasks: Tags: #clang Differential Revision: https://reviews.llvm.org/D103142
2019-08-26FileManager: Use llvm::Expected in new getFileRef APIDuncan P. N. Exon Smith
`FileManager::getFileRef` is a modern API which we expect to convert to over time. We should modernize the error handling as well, using `llvm::Expected` instead of `llvm::ErrorOr`, to help clients that care about errors to ensure nothing is missed. However, not all clients care. I've also added another path for those that don't: - `FileEntryRef` is now copy- and move-assignable (using a pointer instead of a reference). - `FileManager::getOptionalFileRef` returns an `llvm::Optional` instead of `llvm::Expected`. - Added an `llvm::expectedToOptional` utility in case this is useful elsewhere. https://reviews.llvm.org/D66705 llvm-svn: 369943
2019-08-22Introduce FileEntryRef and use it when handling includes to report correct ↵Alex Lorenz
dependencies when the FileManager is reused across invocations This commit introduces a parallel API to FileManager's getFile: getFileEntryRef, which returns a reference to the FileEntry, and the name that was used to access the file. In the case of a VFS with 'use-external-names', the FileEntyRef contains the external name of the file, not the filename that was used to access it. The new API is adopted only in the HeaderSearch and Preprocessor for include file lookup, so that the accessed path can be propagated to SourceManager's FileInfo. SourceManager's FileInfo now can report this accessed path, using the new getName method. This API is then adopted in the dependency collector, which now correctly reports dependencies when a file is included both using a symlink and a real path in the case when the FileManager is reused across multiple Preprocessor invocations. Note that this patch does not fix all dependency collector issues, as the same problem is still present in other cases when dependencies are obtained using FileSkipped, InclusionDirective, and HasInclude. This will be fixed in follow-up commits. Differential Revision: https://reviews.llvm.org/D65907 llvm-svn: 369680
2019-08-01[clang] Adopt new FileManager error-returning APIsHarlan Haskins
Update the callers of FileManager::getFile and FileManager::getDirectory to handle the new llvm::ErrorOr-returning methods. Signed-off-by: Harlan Haskins <harlan@apple.com> llvm-svn: 367616
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-08-20[Lex] Make HeaderMaps a unique_ptr vectorFangrui Song
Summary: unique_ptr makes the ownership clearer than a raw pointer container. Reviewers: Eugene.Zelenko, dblaikie Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D50945 llvm-svn: 340198
2016-10-01Use StringRef for MemoryBuffer identifier API (NFC)Mehdi Amini
llvm-svn: 283043
2016-02-23Lex: Return "" when HeaderMap::lookupFilename failsDuncan P. N. Exon Smith
Change getString() to return Optional<StringRef>, and change lookupFilename() to return an empty string if either one of the prefix and suffix can't be found. This is a more robust follow-up to r261461, but it's still not entirely satisfactory. Ideally we'd report that the header map is corrupt; perhaps something for a follow-up. llvm-svn: 261596
2016-02-22Lex: Check for 0 buckets on header map constructionDuncan P. N. Exon Smith
Switch to using `isPowerOf2_32()` to check whether the buckets are a power of two, and as a side benefit reject loading a header map with no buckets. This is a follow-up to r261448. llvm-svn: 261585
2016-02-21Lex: Never overflow the file in HeaderMap::lookupFilename()Duncan P. N. Exon Smith
If a header map file is corrupt, the strings in the string table may not be null-terminated. The logic here previously relied on `MemoryBuffer` always being null-terminated, but this isn't actually guaranteed by the class AFAICT. Moreover, we're seeing a lot of crash traces at calls to `strlen()` inside of `lookupFilename()`, so something is going wrong there. Instead, use `strnlen()` to get the length, and check for corruption. Also remove code paths that could call `StringRef(nullptr)`. r261459 made these rather obvious (although they'd been there all along). llvm-svn: 261461
2016-02-20Lex: Change HeaderMapImpl::getString() to return StringRef, NFCDuncan P. N. Exon Smith
llvm-svn: 261459
2016-02-20Lex: Use dbgs() instead of fprintf() in HeaderMap::dump()Duncan P. N. Exon Smith
This way it's easy to change HeaderMapImpl::getString() to return a StringRef. There's a slight change here, because I used `errs()` instead of `dbgs()`. But `dbgs()` is more appropriate for a dump method. llvm-svn: 261456
2016-02-20Lex: Check whether the header map buffer has space for the bucketsDuncan P. N. Exon Smith
Check up front whether the header map buffer has space for all of its declared buckets. There was already a check in `getBucket()`, but it had UB (comparing pointers that were outside of objects in the error path) and was insufficient (only checking for a single byte of the relevant bucket). I fixed the check, moved it to `checkHeader()`, and left a fixed version behind as an assertion. llvm-svn: 261449
2016-02-20Lex: Check buckets on header map constructionDuncan P. N. Exon Smith
If the number of buckets is not a power of two, immediately recognize the header map as corrupt, rather than waiting for the first lookup. I converted the later check to an assert. llvm-svn: 261448
2016-02-20Lex: Add some unit tests for corrupt header mapsDuncan P. N. Exon Smith
Split the implementation of `HeaderMap` into `HeaderMapImpl` so that we can write unit tests that don't depend on the `FileManager`, and then write a few tests that cover the types of corrupt header maps already detected. This also moves type and constant definitions from HeaderMap.cpp to HeaderMapTypes.h so that the test can access them. llvm-svn: 261446
2016-01-29Annotate dump() methods with LLVM_DUMP_METHOD, addressing Richard Smith ↵Yaron Keren
r259192 post commit comment. llvm-svn: 259232
2014-10-26Make VFS and FileManager match the current MemoryBuffer API.Benjamin Kramer
This eliminates converting back and forth between the 3 formats and gives us a more homogeneous interface. llvm-svn: 220657
2014-08-29unique_ptrify HeaderMap::FileBufferDavid Blaikie
llvm-svn: 216758
2014-05-17[C++11] Use 'nullptr'. Lex edition.Craig Topper
llvm-svn: 209083
2014-03-09[C++11] Replace OwningPtr include with <memory>.Ahmed Charles
llvm-svn: 203389
2014-03-07Replace OwningPtr with std::unique_ptr.Ahmed Charles
This compiles cleanly with lldb/lld/clang-tools-extra/llvm. llvm-svn: 203279
2014-03-07Change OwningPtr::take() to OwningPtr::release().Ahmed Charles
This is a precursor to moving to std::unique_ptr. llvm-svn: 203275
2014-02-14If the headermap maps the filename to a framework include ("Foo.h" -> ↵Argyrios Kyrtzidis
"Foo/Foo.h"), continue header lookup using the framework include as filename. This allows us to conveniently treat #import "Foo.h" as an implicit module import if we can resolve "Foo/Foo.h" as such. rdar://16042979 llvm-svn: 201419
2013-05-15Use only explicit bool conversion operatorDavid Blaikie
The most common (non-buggy) case are where such objects are used as return expressions in bool-returning functions or as boolean function arguments. In those cases I've used (& added if necessary) a named function to provide the equivalent (or sometimes negative, depending on convenient wording) test. DiagnosticBuilder kept its implicit conversion operator owing to the prevalent use of it in return statements. One bug was found in ExprConstant.cpp involving a comparison of two PointerUnions (PointerUnion did not previously have an operator==, so instead both operands were converted to bool & then compared). A test is included in test/SemaCXX/constant-expression-cxx1y.cpp for the fix (adding operator== to PointerUnion in LLVM). llvm-svn: 181869
2013-02-09Remove some stray uses of <ctype.h> functions.Jordan Rose
These are causing assertions on some MSVC builds. llvm-svn: 174805
2013-02-08Excise <cctype> from Clang (except clang-tblgen) in favor of CharInfo.h.Jordan Rose
Nearly all of these changes are one-to-one replacements; the few that aren't have to do with custom identifier validation. llvm-svn: 174768
2012-09-06Dont cast away const needlessly. Found by gcc48 -Wcast-qual.Roman Divacky
llvm-svn: 163325
2012-02-05Basic: import SmallString<> into clang namespaceDylan Noblesmith
(I was going to fix the TODO about DenseMap too, but that would break self-host right now. See PR11922.) llvm-svn: 149799
2012-02-05Basic: import OwningPtr<> into clang namespaceDylan Noblesmith
llvm-svn: 149798
2011-07-23remove unneeded llvm:: namespace qualifiers on some core types now that ↵Chris Lattner
LLVM.h imports them into the clang namespace. llvm-svn: 135852
2011-04-26To be able to replay compilations we need to accurately remodel howManuel Klimek
includes get resolved, especially when they are found relatively to another include file. We also try to get it working for framework includes, but that part of the code is untested, as I don't have a code base that uses it. llvm-svn: 130246
2011-03-16Add a 'RawPath' parameter to the PPCallbacks interface. This allowsChandler Carruth
clients to observe the exact path through which an #included file was located. This is very useful when trying to record and replay inclusion operations without it beind influenced by the aggressive caching done inside the FileManager to avoid redundant system calls and filesystem operations. The work to compute and return this is only done in the presence of callbacks, so it should have no effect on normal compilation. Patch by Manuel Klimek. llvm-svn: 127742
2010-12-19Add missing standard includes. Patch by Joerg Sonnenberger!Nick Lewycky
llvm-svn: 122194
2010-11-29Merge System into Support.Michael J. Spencer
llvm-svn: 120297
2010-11-23now the FileManager has a FileSystemOpts ivar, stop threadingChris Lattner
FileSystemOpts through a ton of apis, simplifying a lot of code. This also fixes a latent bug in ASTUnit where it would invoke methods on FileManager without creating one in some code paths in cindextext. llvm-svn: 120010