aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Error.cpp
diff options
context:
space:
mode:
authorElliot Goodrich <elliotgoodrich@gmail.com>2023-07-08 10:16:12 +0100
committerElliot Goodrich <elliotgoodrich@gmail.com>2023-07-08 20:06:21 +0100
commit2e2743b6479c9d90c85a0bf68d83d45c7f9f472d (patch)
tree60e5fc93522b1f344235634c8a22a46532ad223a /llvm/lib/Support/Error.cpp
parenta11efd49266f6cf2a98bdf52428b0c9423158846 (diff)
downloadllvm-2e2743b6479c9d90c85a0bf68d83d45c7f9f472d.zip
llvm-2e2743b6479c9d90c85a0bf68d83d45c7f9f472d.tar.gz
llvm-2e2743b6479c9d90c85a0bf68d83d45c7f9f472d.tar.bz2
[Support] Move StringExtras.h include from Error.h to Error.cpp
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
Diffstat (limited to 'llvm/lib/Support/Error.cpp')
-rw-r--r--llvm/lib/Support/Error.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Support/Error.cpp b/llvm/lib/Support/Error.cpp
index b339b70..21d5915 100644
--- a/llvm/lib/Support/Error.cpp
+++ b/llvm/lib/Support/Error.cpp
@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Error.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/ErrorHandling.h"
#include <system_error>
@@ -70,6 +72,15 @@ void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner) {
});
}
+/// Write all error messages (if any) in E to a string. The newline character
+/// is used to separate error messages.
+std::string toString(Error E) {
+ SmallVector<std::string, 2> Errors;
+ handleAllErrors(std::move(E), [&Errors](const ErrorInfoBase &EI) {
+ Errors.push_back(EI.message());
+ });
+ return join(Errors.begin(), Errors.end(), "\n");
+}
std::error_code ErrorList::convertToErrorCode() const {
return std::error_code(static_cast<int>(ErrorErrorCode::MultipleErrors),