aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/SourceManager.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-04-13Add back include for AutoConvert.h as it's needed for z/OS (#135430)Sean Perry1-0/+1
The commit https://github.com/llvm/llvm-project/commit/a1935fd3809772c06f9a09fa151181642ae92b20 removed an include that is needed when building on z/OS.
2025-04-04[clang] Remove unused SourceManager.cpp includes, NFC (trying out clangd)Reid Kleckner1-4/+0
2025-01-14[llvm-project] Fix typos mutli and mutliple. NFC. (#122880)Jay Foad1-1/+1
2024-12-12[SystemZ][z/OS] Replace assert with updated return statement to check if a ↵Abhina Sreeskantharajan1-2/+1
file size will grow due to conversion
2024-12-11[SystemZ][z/OS] Update autoconversion functions to improve support for UTF-8 ↵Abhina Sree1-1/+31
(#98652) This fixes the following error when reading source and header files on z/OS: error: source file is not valid UTF-8
2024-11-21[clang] [NFC] Remove SourceLocation() parameter from Diag.Report() calls in ↵Boaz Brickner1-3/+3
SourceManager, and use the equivalent Report() overload instead (#116937)
2024-11-13[Clang] [NFC] Add "human" diagnostic argument format (#115835)Boaz Brickner1-31/+4
This allows formatting large integers in a human friendly way. Example: "5321584" -> "5.32M". Use it where such human numbers are generated manually today.
2024-11-06[clang] Make source locations space usage diagnostics numbers easier to read ↵Boaz Brickner1-3/+31
(#114999) Instead of writing "12345678B", write "12345678B (12.34MB)".
2024-09-20Revert "[SystemZ][z/OS] Propagate IsText parameter to open text files as ↵Abhina Sreeskantharajan1-12/+2
text (#107906)" This reverts commit edf3b277a5f2ebe144827ed47463c22743cac5f9.
2024-09-19[SystemZ][z/OS] Propagate IsText parameter to open text files as text (#107906)Abhina Sree1-2/+12
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-18Fix OOM in FormatDiagnostic (2nd attempt) (#108866)Vakhurin Sergei1-19/+4
Resolves: #70930 (and probably latest comments from clangd/clangd#251) by fixing racing for the shared DiagStorage value which caused messing with args inside the storage and then formatting the following message with getArgSInt(1) == 2: def err_module_odr_violation_function : Error< "%q0 has different definitions in different modules; " "%select{definition in module '%2'|defined here}1 " "first difference is " which causes HandleSelectModifier to go beyond the ArgumentLen so the recursive call to FormatDiagnostic was made with DiagStr > DiagEnd that leads to infinite while (DiagStr != DiagEnd). The Main Idea: Reuse the existing DiagStorageAllocator logic to make all DiagnosticBuilders having independent states. Also, encapsulating the rest of state (e.g. ID and Loc) into DiagnosticBuilder. The last attempt failed - https://github.com/llvm/llvm-project/pull/108187#issuecomment-2353122096 so was reverted - #108838
2024-09-16Revert "Fix OOM in FormatDiagnostic" (#108838)Aaron Ballman1-4/+19
Reverting due to build failures found in #108187
2024-09-16Fix OOM in FormatDiagnostic (#108187)Vakhurin Sergei1-19/+4
Resolves: #70930 (and probably latest comments from https://github.com/clangd/clangd/issues/251) by fixing racing for the shared `DiagStorage` value which caused messing with args inside the storage and then formatting the following message with `getArgSInt(1)` == 2: ``` def err_module_odr_violation_function : Error< "%q0 has different definitions in different modules; " "%select{definition in module '%2'|defined here}1 " "first difference is " ``` which causes `HandleSelectModifier` to go beyond the `ArgumentLen` so the recursive call to `FormatDiagnostic` was made with `DiagStr` > `DiagEnd` that leads to infinite `while (DiagStr != DiagEnd)`. **The Main Idea:** Reuse the existing `DiagStorageAllocator` logic to make all `DiagnosticBuilder`s having independent states. Also, encapsulating the rest of state (e.g. ID and Loc) into `DiagnosticBuilder`. **TODO (if it will be requested by reviewer):** - [x] add a test (I have no idea how to turn a whole bunch of my proprietary code which leads `clangd` to OOM into a small public example.. probably I must try using [this](https://github.com/llvm/llvm-project/issues/70930#issuecomment-2209872975) instead) - [x] [`Diag.CurDiagID != diag::fatal_too_many_errors`](https://github.com/llvm/llvm-project/pull/108187#pullrequestreview-2296395489) - [ ] ? get rid of `DiagStorageAllocator` at all and make `DiagnosticBuilder` having they own `DiagnosticStorage` coz it seems pretty small so should fit the stack for short-living `DiagnosticBuilder` instances
2024-08-30[clang] Cleanup IncludeLocMap (#106241)kadir çetinkaya1-0/+1
CompilerInstance can re-use same SourceManager across multiple frontendactions. During this process it calls `SourceManager::clearIDTables` to reset any caches based on FileIDs. It didn't reset IncludeLocMap, resulting in wrong include locations for workflows that triggered multiple frontend-actions through same CompilerInstance.
2024-08-16[libclang/python] Expose `clang_isBeforeInTranslationUnit` for ↵Jannick Kremer1-2/+1
`SourceRange.__contains__` Add libclang function `clang_isBeforeInTranslationUnit` to allow checking the order between two source locations. Simplify the `SourceRange.__contains__` implementation using this new function. Add tests for `SourceRange.__contains__` and the newly added functionality. Fixes #22617 Fixes #52827
2024-06-24[SourceManager] Expose max usage of source location space as a Statistic ↵Ilya Biryukov1-0/+17
(#96292) We have been running into source location exhaustion recently and want to use the statistics to monitor the usage in various files to be able to anticipate where the next problem will happen. I picked `Statistic` because it can be written into a structured JSON file and is easier to consume by further automation. This commit does not change any existing per-source-manager metrics exposed via `SourceManager::PrintStats()`. This does create some redundancy, but I also expect to be non-controversial because it aligns with the intended use of `Statistic`.
2024-06-13[Safe Buffers] Serialize unsafe_buffer_usage pragmas (#92031)Ziqing Luo1-0/+18
The commit adds serialization and de-serialization implementations for the stored regions. Basically, the serialized representation of the regions of a PP is a (ordered) sequence of source location encodings. For de-serialization, regions from loaded files are stored by their ASTs. When later one queries if a loaded location L is in an opt-out region, PP looks up the regions of the loaded AST where L is at. (Background if helps: a pair of `#pragma clang unsafe_buffer_usage begin/end` pragmas marks a warning-opt-out region. The begin and end locations (opt-out regions) are stored in preprocessor instances (PP) and will be queried by the `-Wunsafe-buffer-usage` analyzer.) The reported issue at upstream: https://github.com/llvm/llvm-project/issues/90501 rdar://124035402
2024-05-18[clang][NFC] Further improvements to const-correctnessVlad Serebrennikov1-3/+3
2024-05-17[clang][NFC] Improve const-correctness in `SourceManager` (#92436)Vlad Serebrennikov1-0/+4
This patch adds several const-qualified variants of existing member functions to `SourceManager`. I started with removing const qualification from `setNumCreatedFIDsForFileID`, and removing `const_cast` in the body of this function, as I think it doesn't make sense to const-qualify setters.
2023-11-06[clang] Improve `SourceManager::PrintStats()`Jan Svoboda1-5/+7
This fixes a typo ("SLocEntry's" -> "SLocEntries"), fixes capitalization ("Sloc" -> "SLoc") and adds extra information (capacity in bytes of `LoadedSLocEntryTable`).
2023-10-23[Clang] Report an error and crash on source location exhaustion in macros ↵Ilya Biryukov1-5/+11
(#69908) `createExpansionLocImpl` has an assert that checks if we ran out of source locations. We have observed this happening on real code and in release builds the assertion does not fire and the compiler just keeps running indefinitely without giving any indication that something went wrong. Diagnose this problem and reliably crash to make sure the problem is easy to detect. I have also tried: - returning invalid source locations, - reporting sloc address space usage on error. Both caused the compiler to run indefinitely. It would be nice to dig further why that happens, but until then crashing seems like a better alternative.
2023-10-10Use llvm::endianness::{big,little,native} (NFC)Kazu Hirata1-1/+1
Note that llvm::support::endianness has been renamed to llvm::endianness while becoming an enum class as opposed to an enum. This patch replaces llvm::support::{big,little,native} with llvm::endianness::{big,little,native}.
2023-10-06[clang][modules] Move `SLocEntry` search into `ASTReader` (#66966)Jan Svoboda1-65/+5
In `SourceManager::getFileID()`, Clang performs binary search over its buffer of `SLocEntries`. For modules, this binary search fully deserializes the entire `SLocEntry` block for each visited entry. For some entries, that includes decompressing the associated buffer (e.g. the predefines buffer, macro expansion buffers, contents of volatile files), which shows up in profiles of the dependency scanner. This patch moves the binary search over loaded entries into `ASTReader`, which can perform cheaper partial deserialization during the binary search, reducing the wall time of dependency scans by ~3%. This also reduces the number of retired instructions by ~1.4% on regular (implicit) modules compilation. Note that this patch drops the optimizations based on the last lookup ID (pruning the search space and performing linear search before resorting to the full binary search). Instead, it reduces the search space by asking `ASTReader::GlobalSLocOffsetMap` for the containing `ModuleFile` and only does binary search over entries of single module file.
2023-10-06[Basic] Fix a warningKazu Hirata1-1/+2
This patch fixes: clang/lib/Basic/SourceManager.cpp:1979:64: error: 'greater' may not intend to support class template argument deduction [-Werror,-Wctad-maybe-unsupported]
2023-10-06[clang][modules] Remove preloaded SLocEntries from PCM files (#66962)Jan Svoboda1-66/+99
This commit removes the list of SLocEntry offsets to preload eagerly from PCM files. Commit introducing this functionality (258ae54a) doesn't clarify why this would be more performant than the lazy approach used regularly. Currently, the only SLocEntry the reader is supposed to preload is the predefines buffer, but in my experience, it's not actually referenced in most modules, so the time spent deserializing its SLocEntry is wasted. This is especially noticeable in the dependency scanner, where this change brings 4.56% speedup on my benchmark.
2023-10-03[clang] NFCI: Use `FileEntryRef` for `FileID` creation (#67838)Jan Svoboda1-14/+4
This patch removes the `SourceManager` APIs that create `FileID` from a `const FileEntry *` in favor of APIs that take `FileEntryRef`. This also removes a misleading documentation that claims `nullptr` file entry represents stdin. I don't think that's right, since we just try to dereference that pointer anyways.
2023-09-30Introduce paged vector (#66430)Giulio Eulisse1-5/+5
The goal of the class is to be an (almost) drop in replacement for SmallVector and std::vector when those are presized and filled later, as it happens in SourceManager and ASTReader. By doing so, sparsely accessed PagedVector can profit from reduced memory footprint.
2023-09-29[clang] NFCI: Use `FileEntryRef` in ↵Jan Svoboda1-2/+2
`SourceManager::getMemoryBufferForFileOr{None,Fake}()`
2023-09-29[clang] NFCI: Use `FileEntryRef` in `SourceManager::overrideFileContents()`Jan Svoboda1-2/+2
2023-09-29[clang] NFCI: Use `FileEntryRef` in `SourceManager::FileInfos` (#67742)Jan Svoboda1-3/+2
2023-09-28[clang] NFCI: Use `FileEntryRef` in `SourceManager::setFileIsTransient()`Jan Svoboda1-2/+2
2023-09-28[clang][Parser][NFC] Fix a doc comment mishapTimm Bäder1-1/+1
2023-09-13[clang] NFCI: Use `FileEntryRef` in `SrcMgr::ContentCache`Jan Svoboda1-1/+1
2023-09-08Reapply "[clang] NFCI: Adopt `SourceManager::getFileEntryRefForID()`"Jan Svoboda1-1/+1
This reapplies ddbcc10b9e26b18f6a70e23d0611b9da75ffa52f, except for a tiny part that was reverted separately: 65331da0032ab4253a4bc0ddcb2da67664bd86a9. That will be reapplied later on, since it turned out to be more involved. This commit is enabled by 5523fefb01c282c4cbcaf6314a9aaf658c6c145f and f0f548a65a215c450d956dbcedb03656449705b9, specifically the part that makes 'clang-tidy/checkers/misc/header-include-cycle.cpp' separator agnostic.
2023-09-06Revert "[clang] NFCI: Adopt `SourceManager::getFileEntryRefForID()`"Jan Svoboda1-1/+1
This reverts commit ddbcc10b9e26b18f6a70e23d0611b9da75ffa52f. The 'clang-tidy/checkers/misc/header-include-cycle.cpp' test started failing on Windows: https://lab.llvm.org/buildbot/#/builders/216/builds/26855.
2023-09-06[clang] NFCI: Adopt `SourceManager::getFileEntryRefForID()`Jan Svoboda1-1/+1
This commit replaces some calls to the deprecated `FileEntry::getName()` with `FileEntryRef::getName()` by swapping current usages of `SourceManager::getFileEntryForID()` with `SourceManager::getFileEntryRefForID()`. This lowers the number of usages of the deprecated `FileEntry::getName()` from 95 to 50.
2023-05-24LLVM_FALLTHROUGH => [[fallthrough]]. NFCCraig Topper1-1/+1
Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D150996
2023-01-28Use llvm::count{lr}_{zero,one} (NFC)Kazu Hirata1-2/+1
2023-01-14[clang] Remove remaining uses of llvm::Optional (NFC)Kazu Hirata1-1/+0
This patch removes several "using" declarations and #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] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-12/+12
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 Hirata1-0/+1
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-20[Clang] Prepare for llvm::Optional becoming std::optional.Benjamin Kramer1-2/+2
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-3/+2
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-2/+3
2022-12-10Don't include None.h (NFC)Kazu Hirata1-1/+0
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-04Correct typo introduced in f607884a04b0ca06951227a01d00bc59b948d337serge-sans-paille1-1/+1
Fix #59321
2022-12-03[Basic] Use std::nullopt instead of None (NFC)Kazu Hirata1-11/+11
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-30[Basic] Fix a warningKazu Hirata1-1/+1
This patch fixes: clang/lib/Basic/SourceManager.cpp:1292:19: error: comparison of integers of different signs: 'long' and 'unsigned long' [-Werror,-Wsign-compare]
2022-11-30[clang] Speedup LineOffsetMapping::getserge-sans-paille1-23/+25
LineOffsetMapping::get is a critical function that consistently appears in the top 5 more computation intensive functions when running the preprocessor. This change brings consistent speedup of ~.5% on, preprocessing time, see https://llvm-compile-time-tracker.com/compare.php?from=0745b0c0354a0c8e1fefb68a3876d15db6c2e27a&to=460f3f04dac025e6952d78fce104a88151508a29&stat=instructions:u for detailed statistics. Differential Revision: https://reviews.llvm.org/D138474
2022-11-16When we run out of source locations, try to produce useful informationRichard Smith1-0/+91
indicating why we ran out.