aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Error.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-05-05[ErrorHandling] Add reportFatalInternalError + reportFatalUsageError (NFC) ↵Nikita Popov1-0/+7
(#138251) This implements the result of the discussion at: https://discourse.llvm.org/t/rfc-report-fatal-error-and-the-default-value-of-gencrashdialog/73587 There are two different use cases for report_fatal_error, so replace it with two functions reportFatalInternalError() and reportFatalUsageError(). The former indicates a bug in LLVM and generates a crash dialog. The latter does not. The names have been suggested by rnk and people seemed to like them. This replaces a lot of the usages that passed an explicit value for GenCrashDiag. I did not bulk replace remaining report_fatal_error usage -- they probably require case by case review for which function to use.
2024-07-31Add llvm::Error C API, LLVMCantFailDavid Blaikie1-0/+6
It's barely testable - the test does exercise the code, but wouldn't fail on an empty implementation. It would cause a memory leak though (because the error handle wouldn't be unwrapped/reowned) which could be detected by asan and other leak detectors.
2024-06-14[Error] Add non-consuming toString (#95375)Nikita Popov1-0/+8
There are some places that want to convert an Error to string, but still retain the original Error object, for example to emit a non-fatal warning. This currently isn't possible, because the entire Error infra is move-based. And what people end up doing in this case is to move the Error... twice. This patch introduces a toStringWithoutConsuming() function to accommodate this use case. This also requires some infrastructure that allows visiting Errors without consuming them.
2024-05-23Avoid std::string -> (char *) roundtrip in createStringError() (NFC) (#93242)Adrian Prantl1-1/+4
The current API first creates a temporary std::string, then passes it as a C string, only to then convert it into a std::string for storage, thus unnecessarily computing the length of the string and copying it.
2023-07-13[Support] Move StringExtras.h include from Error.h to Error.cppElliot Goodrich1-0/+11
Move the implementation of the `toString` function from `llvm/Support/Error.h` to the source file, which allows us to move `#include "llvm/ADT/StringExtras.h"` to the source file as well. As `Error.h` is present in a large number of translation units this means we are unnecessarily bringing in the contents of `StringExtras.h` - itself a large file with lots of includes - and slowing down compilation. Also move the `#include "llvm/ADT/SmallVector.h"` directive to the source file as it's no longer needed, but this does not give as much of a benefit. This reduces the total number of preprocessing tokens across the LLVM source files in lib from (roughly) 1,920,413,050 to 1,903,629,230 - a reduction of ~0.87%. This should result in a small improvement in compilation time. Differential Revision: https://reviews.llvm.org/D155178
2023-07-13Revert "[Support] Move StringExtras.h include from Error.h to Error.cpp"Elliot Goodrich1-11/+0
This reverts commit 5be8c89ed6d959d57ae21c168dc4215ce0d05553.
2023-07-13[Support] Move StringExtras.h include from Error.h to Error.cppElliot Goodrich1-0/+11
Move the implementation of the `toString` function from `llvm/Support/Error.h` to the source file, which allows us to move `#include "llvm/ADT/StringExtras.h"` to the source file as well. As `Error.h` is present in a large number of translation units this means we are unnecessarily bringing in the contents of `StringExtras.h` - itself a large file with lots of includes - and slowing down compilation. Also move the `#include "llvm/ADT/SmallVector.h"` directive to the source file as it's no longer needed, but this does not give as much of a benefit. This reduces the total number of preprocessing tokens across the LLVM source files in lib from (roughly) 1,920,413,050 to 1,903,629,230 - a reduction of ~0.87%. This should result in a small improvement in compilation time. Differential Revision: https://reviews.llvm.org/D155018
2023-07-09Revert "[Support] Move StringExtras.h include from Error.h to Error.cpp"Elliot Goodrich1-11/+0
This reverts commit 4c0cfd870f78c3f107b23a2bd61504c8ebc22912. There are still transitive includes missing inside lldb tools.
2023-07-09[Support] Move StringExtras.h include from Error.h to Error.cppElliot Goodrich1-0/+11
Move the implementation of the `toString` function from `llvm/Support/Error.h` to the source file, which allows us to move `#include "llvm/ADT/StringExtras.h"` to the source file as well. As `Error.h` is present in a large number of translation units this means we are unnecessarily bringing in the contents of `StringExtras.h` - itself a large file with lots of includes - and slowing down compilation. Also move the `#include "llvm/ADT/SmallVector.h"` directive to the source file as it's no longer needed, but this does not give as much of a benefit. This reduces the total number of preprocessing tokens across the LLVM source files in lib from (roughly) 1,920,413,050 to 1,903,629,230 - a reduction of ~0.87%. This should result in a small improvement in compilation time. Differential Revision: https://reviews.llvm.org/D154775
2023-07-08Revert "[Support] Move StringExtras.h include from Error.h to Error.cpp"Elliot Goodrich1-11/+0
This reverts commit 2e2743b6479c9d90c85a0bf68d83d45c7f9f472d. More transitive includes of `llvm/ADT/StringExtras.h` need to be removed.
2023-07-08[Support] Move StringExtras.h include from Error.h to Error.cppElliot Goodrich1-0/+11
Move the implementation of the `toString` function from `llvm/Support/Error.h` to the source file, which allows us to move `#include "llvm/ADT/StringExtras.h"` to the source file as well. As `Error.h` is present in a large number of translation units this means we are unnecessarily bringing in the contents of `StringExtras.h` - itself a large file with lots of includes - and slowing down compilation. Also move the `#include "llvm/ADT/SmallVector.h"` directive to the source file as it's no longer needed, but this does not give as much of a benefit. This reduces the total number of preprocessing tokens across the LLVM source files in lib from (roughly) 1,920,413,050 to 1,903,629,230 - a reduction of ~0.87%. This should result in a small improvement in compilation time. Differential Revision: https://reviews.llvm.org/D154763
2023-07-08Revert "[Support] Move StringExtras.h include from Error.h to Error.cpp"Elliot Goodrich1-11/+0
This reverts commit fc6b12689c5001aa050fc1d855209a5e319112b7.
2023-07-08[Support] Move StringExtras.h include from Error.h to Error.cppElliot Goodrich1-0/+11
Move the implementation of the `toString` function from `llvm/Support/Error.h` to the source file, which allows us to move `#include "llvm/ADT/StringExtras.h"` to the source file as well. As `Error.h` is present in a large number of translation units this means we are unnecessarily bringing in the contents of `StringExtras.h` - itself a large file with lots of includes - and slowing down compilation. Also move the `#include "llvm/ADT/SmallVector.h"` directive to the source file as it's no longer needed, but this does not give as much of a benefit. This reduces the total number of preprocessing tokens across the LLVM source files in lib from (roughly) 1,920,413,050 to 1,903,629,230 - a reduction of ~0.87%. This should result in a small improvement in compilation time. Differential Revision: https://reviews.llvm.org/D154543
2023-06-25Revert "[llvm] Move StringExtras.h include from Error.h to Error.cpp"Elliot Goodrich1-11/+0
This reverts commit 2fa0dbd7bf353db98b27b56137cced0a67de2748.
2023-06-25[llvm] Move StringExtras.h include from Error.h to Error.cppElliot Goodrich1-0/+11
Move the implementation of the `toString` function from `llvm/Support/Error.h` to the source file, which allows us to move `#include "llvm/ADT/StringExtras.h"` to the source file as well. As `Error.h` is present in a large number of translation units this means we are unnecessarily bringing in the contents of `StringExtras.h` - itself a large file with lots of includes - and slowing down compilation. Also move the `#include "llvm/ADT/SmallVector.h"` directive to the source file as it's no longer needed, but this does not give as much of a benefit. This reduces the total number of preprocessing tokens across the LLVM source files in lib from (roughly) 1,920,413,050 to 1,903,629,230 - a reduction of ~0.87%. This should result in a small improvement in compilation time. Differential Revision: https://reviews.llvm.org/D153229
2023-05-17[Support] Forward GenCrashDiag argument from report_fatal_error(Error, bool)Alex Bradbury1-1/+1
The boolean GenCrashDiag argument was previous just discarded, which seems to be an oversight that existed when this overload was first added. Differential Revision: https://reviews.llvm.org/D150669
2022-07-10ManagedStatic: remove many straightforward uses in llvmNicolai Hähnle1-5/+7
(Reapply after revert in e9ce1a588030d8d4004f5d7e443afe46245e9a92 due to Fuchsia test failures. Removed changes in lib/ExecutionEngine/ other than error categories, to be checked in more detail and reapplied separately.) Bulk remove many of the more trivial uses of ManagedStatic in the llvm directory, either by defining a new getter function or, in many cases, moving the static variable directly into the only function that uses it. Differential Revision: https://reviews.llvm.org/D129120
2022-07-10Revert "ManagedStatic: remove many straightforward uses in llvm"Nicolai Hähnle1-7/+5
This reverts commit e6f1f062457c928c18a88c612f39d9e168f65a85. Reverting due to a failure on the fuchsia-x86_64-linux buildbot.
2022-07-10ManagedStatic: remove many straightforward uses in llvmNicolai Hähnle1-5/+7
Bulk remove many of the more trivial uses of ManagedStatic in the llvm directory, either by defining a new getter function or, in many cases, moving the static variable directly into the only function that uses it. Differential Revision: https://reviews.llvm.org/D129120
2021-11-12Support: Pass wrapped Error's error code through FileErrorDuncan P. N. Exon Smith1-2/+5
Change FileError to pass through the error code from the Error it wraps. This allows APIs that return ECError to transition to FileError without changing returned std::error_code. This was extracted from https://reviews.llvm.org/D109345. Differential Revision: https://reviews.llvm.org/D113225
2021-10-06[llvm] Replace report_fatal_error(std::string) uses with ↵Simon Pilgrim1-2/+2
report_fatal_error(Twine) As described on D111049, we're trying to remove the <string> dependency from error handling and replace uses of report_fatal_error(const std::string&) with the Twine() variant which can be forward declared.
2020-10-19[Support] Add a C-API function to create a StringError instance.Lang Hames1-0/+4
This will allow C API clients to return errors from callbacks. This functionality will be used in upcoming Orc C-bindings functions.
2019-11-20[Error] Remove a broken code fragment accidentally included in 76bcbaafab2.Lang Hames1-2/+0
2019-11-20[Orc][Modules] Fix Modules build fallout from a34680a33eb.Lang Hames1-2/+5
In a34680a33eb OrcError.h and Orc/RPC/*.h were split out from the rest of ExecutionEngine in order to eliminate false dependencies for remote JIT targets (see https://reviews.llvm.org/D68732), however this broke modules builds (see https://reviews.llvm.org/D69817). This patch splits these headers out into a separate module, LLVM_OrcSupport, in order to fix the modules build. Fixes <rdar://56377508>.
2019-09-10Move LLVM_ENABLE_ABI_BREAKING_CHECKS variables to their own fileEric Christopher1-15/+0
so that you don't have to link Error.o and all of its dependencies. In more detail: global initializers in Error.o can't be elided with -ffunction-sections/-gc-sections since they always need to be run causing a fairly significant binary bloat if all you want is the ABI breaking checks code. Differential Revision: https://reviews.llvm.org/D67387 llvm-svn: 371561
2019-08-15[llvm] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere1-1/+1
Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. llvm-svn: 369013
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
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-12-30[NFC] Fixed extra semicolon warningDavid Bolvansky1-1/+1
-This line, and those below, will be ignored-- M lib/Support/Error.cpp llvm-svn: 350162
2018-12-29Add vtable anchor to classes.Richard Trieu1-0/+1
llvm-svn: 350142
2018-11-11[Support] Make error banner optional in logAllUnhandledErrorsJonas Devlieghere1-1/+1
In a lot of places an empty string was passed as the ErrorBanner to logAllUnhandledErrors. This patch makes that argument optional to simplify the call sites. llvm-svn: 346604
2018-08-30[Error] Add FileError helper; upgrade StringError behaviorAlexandre Ganea1-2/+22
FileError is meant to encapsulate both an Error and a file name/path. It should be used in cases where an Error occurs deep down the call chain, and we want to return it to the caller along with the file name. StringError was updated to display the error messages in different ways. These can be: 1. display the error_code message, and convert to the same error_code (ECError behavior) 2. display an arbitrary string, and convert to a provided error_code (current StringError behavior) 3. display both an error_code message and a string, in this order; and convert to the same error_code These behaviors can be triggered depending on the constructor. The goal is to use StringError as a base class, when a library needs to provide a explicit Error type. Differential Revision: https://reviews.llvm.org/D50807 llvm-svn: 341064
2018-08-15[Support] Add a basic C API for llvm::Error.Lang Hames1-0/+20
Summary: The C-API supports consuming errors, converting an error to a string error message, and querying an error's type. Other LLVM C APIs that wish to use llvm::Error can supply error-type-id checkers and custom error-to-structured-type converters for any custom errors they provide. Reviewers: bogner, zturner, labath, dblaikie Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D50716 llvm-svn: 339802
2018-07-26[Support] Introduce createStringError helper functionVictor Leschuk1-0/+4
The function in question is copy-pasted lots of times in DWARF-related classes. Thus it will make sense to place its implementation into the Support library. Reviewed by: lhames Differential Revision: https://reviews.llvm.org/D49824 llvm-svn: 337995
2017-11-09[Support] Make llvm::Error and Expected faster.Zachary Turner1-0/+12
Whenever LLVM_ENABLE_ABI_BREAKING_CHECKS is enabled, which is usually the case for example when asserts are enabled, Error's destructor does some additional checking to make sure that that it does not represent an error condition and that it was checked. However, this is -- by definition -- not the likely codepath. Some profiling shows that at least with some compilers, simply calling assertIsChecked -- in a release build with full optimizations -- can account for up to 15% of the entire runtime of the program, even though this function should almost literally be a no-op. The problem is that the assertIsChecked function can be considered too big to inline depending on the compiler's inliner. Since it's unlikely to ever need to failure path though, we can move it out of line and force it to not be inlined, so that the fast path can be inlined. In my test (using lld to link clang with CMAKE_BUILD_TYPE=Release and LLVM_ENABLE_ASSERTIONS=ON), this reduces link time from 27 seconds to 23.5 seconds, which is a solid 15% gain. llvm-svn: 317824
2017-10-11Revert "[ADT] Make Twine's copy constructor private."Zachary Turner1-1/+1
This reverts commit 4e4ee1c507e2707bb3c208e1e1b6551c3015cbf5. This is failing due to some code that isn't built on MSVC so I didn't catch. Not immediately obvious how to fix this at first glance, so I'm reverting for now. llvm-svn: 315536
2017-10-11[ADT] Make Twine's copy constructor private.Zachary Turner1-1/+1
There's a lot of misuse of Twine scattered around LLVM. This ranges in severity from benign (returning a Twine from a function by value that is just a string literal) to pretty sketchy (storing a Twine by value in a class). While there are some uses for copying Twines, most of the very compelling ones are confined to the Twine class implementation itself, and other uses are either dubious or easily worked around. This patch makes Twine's copy constructor private, and fixes up all callsites. Differential Revision: https://reviews.llvm.org/D38767 llvm-svn: 315530
2017-06-06Sort the remaining #include lines in include/... and lib/....Chandler Carruth1-1/+0
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
2016-11-29Fix a linefeed at eof.NAKAMURA Takumi1-1/+1
llvm-svn: 288167
2016-11-28Add link-time detection of LLVM_ABI_BREAKING_CHECKS mismatchMehdi Amini1-0/+15
The macro LLVM_ENABLE_ABI_BREAKING_CHECKS is moved to a new header abi-breaking.h, from llvm-config.h. Only headers that are using the macro are including this new header. LLVM will define a symbol, either EnableABIBreakingChecks or DisableABIBreakingChecks depending on the configuration setting for LLVM_ABI_BREAKING_CHECKS. The abi-breaking.h header will add weak references to these symbols in every clients that includes this header. This should ensure that a mismatch triggers a link failure (or a load time failure for DSO). On MSVC, the pragma "detect_mismatch" is used instead. Differential Revision: https://reviews.llvm.org/D26876 llvm-svn: 288082
2016-11-18Revert "Add link-time detection of LLVM_ABI_BREAKING_CHECKS mismatch"Mehdi Amini1-16/+0
This reverts commit r287352, LLDB CI is broken. llvm-svn: 287374
2016-11-18Add link-time detection of LLVM_ABI_BREAKING_CHECKS mismatchMehdi Amini1-0/+16
Summary: LLVM will define a symbol, either EnableABIBreakingChecks or DisableABIBreakingChecks depending on the configuration setting for LLVM_ABI_BREAKING_CHECKS. The llvm-config.h header will add weak references to these symbols in every clients that includes this header. This should ensure that a mismatch triggers a link failure (or a load time failure for DSO). On MSVC, the pragma "detect_mismatch" is used instead. Reviewers: rnk, jroelofs Subscribers: llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D26841 llvm-svn: 287352
2016-10-19Remove LLVM_NOEXCEPT and replace it with noexceptReid Kleckner1-1/+1
Now that we have dropped MSVC 2013, all supported compilers support noexcept and we can drop this portability macro. llvm-svn: 284672
2016-09-14Missing includes.Vassil Vassilev1-0/+1
llvm-svn: 281450
2016-07-14[Object] Re-apply r275316 now that I have the corresponding LLD patch ready.Lang Hames1-0/+11
llvm-svn: 275361
2016-07-14[Object] Revert r275316, Archive::child_iterator changes, while I update lld.Lang Hames1-11/+0
Should fix the bots broken by r275316. llvm-svn: 275353
2016-07-13[Object] Change Archive::child_iterator for better interop with Error/Expected.Lang Hames1-0/+11
See http://reviews.llvm.org/D22079 Changes the Archive::child_begin and Archive::children to require a reference to an Error. If iterator increment fails (because the archive header is damaged) the iterator will be set to 'end()', and the error stored in the given Error&. The Error value should be checked by the user immediately after the loop. E.g.: Error Err; for (auto &C : A->children(Err)) { // Do something with archive child C. } // Check the error immediately after the loop. if (Err) return Err; Failure to check the Error will result in an abort() when the Error goes out of scope (as guaranteed by the Error class). llvm-svn: 275316
2016-07-04[Support][Error] Make logAllUnhandledErrors take a Twine for the banner, ratherLang Hames1-0/+9
than a const string&. llvm-svn: 274526
2016-05-27Linker: teach the IR mover to return llvm::Error.Peter Collingbourne1-1/+0
This will be needed in order to consistently return an Error to clients of the API being developed in D20268. Differential Revision: http://reviews.llvm.org/D20550 llvm-svn: 270967
2016-05-27[Support] Rename unconvertibleErrorCode to inconvertibleErrorCode.Lang Hames1-6/+6
Based on a totally scientific, 30 second google search "in-" appears to be the preferred prefix. llvm-svn: 270950
2016-05-27[Support] Add a StringError convenience class to Error.hLang Hames1-4/+48
StringError can be used to represent Errors that aren't recoverable based on the error type, but that have a useful error message that can be reported to the user or logged. llvm-svn: 270948