summaryrefslogtreecommitdiff
path: root/llvm/lib/Support/SourceMgr.cpp
AgeCommit message (Collapse)Author
2025-10-17[support] Don't require VFS in `SourceMgr` for loading includes (#163862)Jan Svoboda
This commit more gracefully handles situations where `SourceMgr` isn't initialized with a VFS and tries to resolve an include. That's what happens with the test case `clang -flto=thin -c test.c -o /dev/null` where test.c contains `asm(" .incbin \"foo.i\" \n");`. Propagating the actual VFS all the way is very difficult. This is a follow-up to #162903.
2025-10-15[support] Use VFS in `SourceMgr` for loading includes (#162903)Jan Svoboda
Most `SourceMgr` clients don't make use of include files, but those that do might want to specify the file system to use. This patch enables that by making it possible to pass a `vfs::FileSystem` instance into `SourceMgr`.
2025-09-24[Support] Use list-initialization for returning pairs (#160447)Kazu Hirata
In C++17 and later, "return {A, B};" guarantees copy elision for a std::pair return type, ensuring the object is constructed directly in the return slot. This patch updates those instances under Support/.
2024-08-04[llvm] Construct SmallVector with ArrayRef (NFC) (#101872)Kazu Hirata
2024-05-14[Support] Add option to print SMDiagnostic into a buffer without the ↵Artem Chikin
filename and location info (#92050)
2023-09-01[llvm] Fix duplicate word typos. NFCFangrui Song
Those fixes were taken from https://reviews.llvm.org/D137338
2023-01-09[TableGen][SourceMgr] Fix obvious mistake in D141220Markus Böck
It now tried to open the IncludedFile instead of the Filename, which was not intended.
2023-01-09[TableGen][SourceMgr] Correctly append filename to include directoriesMarkus Böck
The current implementation unconditionally appends the system path separator with the filename to the include directory. This is not correct in edge cases however, such as when specifying `/` as include directory (on Unix systems) or just `\` on Windows. This patch fixes that by using `sys::path::append`, which already has the required logic to correctly implement this. While this is technically only a change in the `SourceMgr` class, I think the main user of that class, and the include mechanism, is TableGen. No test attached because no behavioral difference is observable without trying to access the root directory of the users filesystem. The motivation for this change is a rather funny story, as this actually fixes a performance problem when running `check-mlir` on Windows. Some tests for `mlir-pdll-lsp-server` lead to adding `\` as include directory in TableGen (which is a valid absolute path on Windows!). Due to the unconditional append, the created filepath would then be of the form `\\<dir>\...` which is also a valid path on Windows, but is a network path. On my machine it'd then attempt to access the network and find a machine with the name `<dir>` and the file there. This call would take several seconds, leading to some tests in `mlir-pdll-lsp-server` taking 2 minutes on my machine. Running `check-mlir` after this patch reduces the runtime on my machine from 161 seconds to 6 seconds. Differential Revision: https://reviews.llvm.org/D141220
2023-01-05Move from llvm::makeArrayRef to ArrayRef deduction guides - llvm/ partserge-sans-paille
Use deduction guides instead of helper functions. The only non-automatic changes have been: 1. ArrayRef(some_uint8_pointer, 0) needs to be changed into ArrayRef(some_uint8_pointer, (size_t)0) to avoid an ambiguous call with ArrayRef((uint8_t*), (uint8_t*)) 2. CVSymbol sym(makeArrayRef(symStorage)); needed to be rewritten as CVSymbol sym{ArrayRef(symStorage)}; otherwise the compiler is confused and thinks we have a (bad) function prototype. There was a few similar situation across the codebase. 3. ADL doesn't seem to work the same for deduction-guides and functions, so at some point the llvm namespace must be explicitly stated. 4. The "reference mode" of makeArrayRef(ArrayRef<T> &) that acts as no-op is not supported (a constructor cannot achieve that). Per reviewers' comment, some useless makeArrayRef have been removed in the process. This is a follow-up to https://reviews.llvm.org/D140896 that introduced the deduction guides. Differential Revision: https://reviews.llvm.org/D140955
2022-03-03[PDLL] Add support for tablegen includes and importing ODS informationRiver Riddle
This commit adds support for processing tablegen include files, and importing various information from ODS. This includes operations, attribute+type constraints, attribute/operation/type interfaces, etc. This will allow for much more robust tooling, and also allows for referencing ODS constructs directly within PDLL (imported interfaces can be used as constraints, operation result names can be used for member access, etc). Differential Revision: https://reviews.llvm.org/D119900
2021-12-10[Support] Use range-based for loops (NFC)Kazu Hirata
2021-01-04[llvm] Use llvm::any_of (NFC)Kazu Hirata
2020-12-26[NFC] Refactor some SourceMgr codeNathan James
2020-10-02[TableGen] New backend to print detailed records.Paul C. Anagnostopoulos
Pertinent lints are fixed.
2020-06-08[Support] Replace 'DisableColors' boolean with 'ColorMode' enumJonas Devlieghere
Replace the DisableColors with a ColorMode which can be set to Auto, Enabled and Disabled. The purpose of this change is to make it possible to ignore the command line option not only for disabling colors, but also for enabling them. Differential revision: https://reviews.llvm.org/D81056
2020-04-25[SourceMgr] Tidy up the SourceMgr header file to include less stuff.Chris Lattner
Summary: Specifically make some simple refactorings to get PointerUnion.h and Twine.h out of the public includes. While here, trim out a lot of transitive includes as well. Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78870
2020-04-25[SourceMgr/MLIR diagnostics] Introduce a new method to speed things upChris Lattner
Summary: This introduces a new SourceMgr::FindLocForLineAndColumn method that uses the OffsetCache in SourceMgr::SrcBuffer to do do a constant time lookup for the line number (once the cache is populated). Use this method in MLIR's SourceMgrDiagnosticHandler::convertLocToSMLoc, replacing the O(n) scanning logic. This resolves a long standing TODO in MLIR, and makes one of my usecases go dramatically faster (which is currently producing many diagnostics in a 40MB SourceBuffer). NFC, this is just a performance speedup and cleanup. Reviewers: rriddle!, ftynse! Subscribers: hiraditya, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, grosul1, frgossen, Kayjukh, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78868
2020-01-28Make llvm::StringRef to std::string conversions explicit.Benjamin Kramer
This is how it should've been and brings it more in line with std::string_view. There should be no functional change here. This is mostly mechanical from a custom clang-tidy check, with a lot of manual fixups. It uncovers a lot of minor inefficiencies. This doesn't actually modify StringRef yet, I'll do that in a follow-up.
2019-06-21Simplify std::lower_bound with llvm::{bsearch,lower_bound}. NFCFangrui Song
llvm-svn: 364006
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-10-24[SourceMgr][FileCheck] Obey -color by extending WithColorJoel E. Denny
(Relands r344930, reverted in r344935, and now hopefully fixed for Windows.) While this change specifically targets FileCheck, it affects any tool using the same SourceMgr facilities. Previously, -color was documented in FileCheck's -help output, but -color had no effect. Now, -color obeys its documentation: it forces colors to be used in FileCheck diagnostics even when stderr is not a terminal. -color is especially helpful when combined with FileCheck's -v, which can produce a long series of diagnostics that you might wish to pipe to a pager, such as less -R. The WithColor extensions here will also help to clean up color usage in FileCheck's annotated dump of input, which is proposed in D52999. Reviewed By: JDevlieghere, zturner Differential Revision: https://reviews.llvm.org/D53419 llvm-svn: 345202
2018-10-22Revert r344930 as it broke some of the bots on Windows.Aaron Ballman
http://lab.llvm.org:8011/builders/clang-x64-windows-msvc/builds/739 llvm-svn: 344935
2018-10-22[SourceMgr][FileCheck] Obey -color by extending WithColorJoel E. Denny
While this change specifically targets FileCheck, it affects any tool using the same SourceMgr facilities. Previously, -color was documented in FileCheck's -help output, but -color had no effect. Now, -color obeys its documentation: it forces colors to be used in FileCheck diagnostics even when stderr is not a terminal. -color is especially helpful when combined with FileCheck's -v, which can produce a long series of diagnostics that you might wish to pipe to a pager, such as less -R. The WithColor extensions here will also help to clean up color usage in FileCheck's annotated dump of input, which is proposed in D52999. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D53419 llvm-svn: 344930
2018-09-27llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)Fangrui Song
Summary: The convenience wrapper in STLExtras is available since rL342102. Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits Differential Revision: https://reviews.llvm.org/D52573 llvm-svn: 343163
2018-09-05[Windows] Convert from UTF-8 to UTF-16 when writing to a Windows consoleReid Kleckner
Summary: Calling WriteConsoleW is the most reliable way to print Unicode characters to a Windows console. If binary data gets printed to the console, attempting to re-encode it shouldn't be a problem, since garbage in can produce garbage out. This breaks printing strings in the local codepage, which WriteConsoleA knows how to handle. For example, this can happen when user source code is encoded with the local codepage, and an LLVM tool quotes it while emitting a caret diagnostic. This is unfortunate, but well-behaved tools should validate that their input is UTF-8 and escape non-UTF-8 characters before sending them to raw_fd_ostream. Clang already does this, but not all LLVM tools do this. One drawback to the current implementation is printing a string a byte at a time doesn't work. Consider this LLVM code: for (char C : MyStr) outs() << C; Because outs() is now unbuffered, we wil try to convert each byte to UTF-16, which will fail. However, this already didn't work, so I think we may as well update callers that do that as we find them to print complete portions of strings. You can see a real example of this in my patch to SourceMgr.cpp Fixes PR38669 and PR36267. Reviewers: zturner, efriedma Subscribers: llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D51558 llvm-svn: 341433
2018-07-30Remove trailing spaceFangrui Song
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338293
2018-07-17Don't assert that a size_t fits into 64bit.Joerg Sonnenberger
Avoids tautological compare warnings on 32bit platforms. llvm-svn: 337269
2018-04-08[Support] Change std::sort to llvm::sort in response to r327219Mandeep Singh Grang
Summary: r327219 added wrappers to std::sort which randomly shuffle the container before sorting. This will help in uncovering non-determinism caused due to undefined sorting order of objects having the same key. To make use of that infrastructure we need to invoke llvm::sort instead of std::sort. Note: This patch is one of a series of patches to replace *all* std::sort to llvm::sort. Refer the comments section in D44363 for a list of all the required patches. Reviewers: chandlerc, jordan_rose, bkramer Reviewed By: bkramer Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D45140 llvm-svn: 329536
2018-04-07[Support] Make line-number cache robust against access patterns.Graydon Hoare
Summary: The LLVM SourceMgr class (which is used indirectly by Swift, though not Clang) has a routine for looking up line numbers of SMLocs. This routine uses a shared, special-purpose cache that handles exactly one access pattern efficiently: looking up the line number of an SMLoc that points into the same buffer as the last query made to the SourceMgr, at a location in the buffer at or ahead of the last query. When this works it's fine, but when it fails it's catastrophic for performancer: one recent out-of-order access from a Swift utility routine ran for tens of seconds, spending 99% of its time repeatedly scanning buffers for '\n'. This change removes the shared cache from the SourceMgr and installs a new cache in each SrcBuffer. The per-SrcBuffer caches are also "full", in the sense that rather than caching a single last-query pointer, they cache _all_ the line-ending offsets, in a binary-searchable array, such that once it's populated (on first access), all subsequent access patterns run at the same speed. Performance measurements I've done show this is actually a little bit faster on real codebases (though only a couple fractions of a percent). Memory usage is up by a few tens to hundreds of bytes per SrcBuffer that has a line lookup done on it; I've attempted to minimize this by using dynamic selection of integer sized when storing offset arrays. But the main motive here is to make-impossible the cases we don't always see, that show up by surprise when there is an out-of-order access pattern. Reviewers: jordan_rose Reviewed By: jordan_rose Subscribers: probinson, llvm-commits Differential Revision: https://reviews.llvm.org/D45003 llvm-svn: 329470
2017-10-12Add DK_Remark to SMDiagnosticAdam Nemet
Swift uses SMDiagnostic for diagnostic messages. For https://github.com/apple/swift/pull/12294, we need remark support. I picked the color that clang uses to display them. Differential Revision: https://reviews.llvm.org/D38865 llvm-svn: 315642
2017-06-06Sort the remaining #include lines in include/... and lib/....Chandler Carruth
I did this a long time ago with a janky python script, but now clang-format has built-in support for this. I fed clang-format every line with a #include and let it re-sort things according to the precise LLVM rules for include ordering baked into clang-format these days. I've reverted a number of files where the results of sorting includes isn't healthy. Either places where we have legacy code relying on particular include ordering (where possible, I'll fix these separately) or where we have particular formatting around #include lines that I didn't want to disturb in this patch. This patch is *entirely* mechanical. If you get merge conflicts or anything, just ignore the changes in this patch and run clang-format over your #include lines in the files. Sorry for any noise here, but it is important to keep these things stable. I was seeing an increasing number of patches with irrelevant re-ordering of #include lines because clang-format was used. This patch at least isolates that churn, makes it easy to skip when resolving conflicts, and gets us to a clean baseline (again). llvm-svn: 304787
2017-05-01Remove unnecessary conditions as suggested by clang-tidy. NFCGabor Horvath
Patch by: Gergely Angeli! Differential Revision: https://reviews.llvm.org/D31936 llvm-svn: 301807
2017-02-15[Support] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko
other minor fixes (NFC). llvm-svn: 295243
2016-10-01Use StringRef for MemoryBuffer identifier API (NFC)Mehdi Amini
llvm-svn: 283043
2016-08-16Remove excessive padding from LineNoCacheTyBenjamin Kramer
The struct LineNoCacheTy is in SourceMgr.cpp inside anonymous namespace. This diff changes the order of fields and removes the excessive padding (8 bytes). Patch by Alexander Shaposhnikov! Differential revision: https://reviews.llvm.org/D23546 llvm-svn: 278838
2016-08-12Use the range variant of find_if instead of unpacking begin/endDavid Majnemer
No functionality change is intended. llvm-svn: 278443
2015-06-15MIR Serialization: Connect the machine function analysis pass to the MIR parser.Alex Lorenz
This commit connects the machine function analysis pass (which creates machine functions) to the MIR parser, which will initialize the machine functions with the state from the MIR file and reconstruct the machine IR. This commit introduces a new interface called 'MachineFunctionInitializer', which can be used to provide custom initialization for the machine functions. This commit also introduces a new diagnostic class called 'DiagnosticInfoMIRParser' which is used for MIR parsing errors. This commit modifies the default diagnostic handling in LLVMContext - now the the diagnostics are printed directly into llvm::errs() so that the MIR parsing errors can be printed with colours. Reviewers: Justin Bogner Differential Revision: http://reviews.llvm.org/D9928 llvm-svn: 239753
2015-03-23Purge unused includes throughout libSupport.Benjamin Kramer
NFC. llvm-svn: 232976
2014-11-06Remove unnecessary .c_str() when implicitly converting to TwineMatt Arsenault
llvm-svn: 221422
2014-08-21Explicitly pass ownership of the MemoryBuffer to AddNewSourceBuffer using ↵David Blaikie
std::unique_ptr llvm-svn: 216223
2014-07-09SourceMgr: consistently use 'unsigned' for the memory buffer ID typeDmitri Gribenko
llvm-svn: 212595
2014-07-06Update the MemoryBuffer API to use ErrorOr.Rafael Espindola
llvm-svn: 212405
2014-07-06SourceMgr: make valid buffer IDs start from oneAlp Toker
Use 0 for the invalid buffer instead of -1/~0 and switch to unsigned representation to enable more idiomatic usage. Also introduce a trivial SourceMgr::getMainFileID() instead of hard-coding 0/1 to identify the main file. llvm-svn: 212398
2014-06-25Use SourceMgr::getMemoryBuffer() in a couple of placesAlp Toker
Cleanup only. llvm-svn: 211656
2014-06-17Add an overload for SourceMgr::PrintMessage that takes an existing diagnostic.Jordan Rose
llvm-svn: 211087
2014-06-17Modernize doc comments for SourceMgr.Jordan Rose
No functionality change. llvm-svn: 211086
2014-06-12Remove system_error.h.Rafael Espindola
This is a minimal change to remove the header. I will remove the occurrences of "using std::error_code" in a followup patch. llvm-svn: 210803
2014-05-16Fix hardcoded slash to native path seperator which was exposed from ↵Yaron Keren
llvm::sys::path. http://reviews.llvm.org/D3687 llvm-svn: 208980
2014-04-09[C++11] Replace some comparisons with 'nullptr' with simple boolean checks ↵Craig Topper
to reduce verbosity. llvm-svn: 205829
2014-04-07[C++11] Make use of 'nullptr' in the Support library.Craig Topper
llvm-svn: 205697