diff options
author | Geoffrey Martin-Noble <gcmn@google.com> | 2020-09-02 15:00:26 -0700 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2020-09-02 15:00:26 -0700 |
commit | 848b0e244c9ff5413c2eee6357d5faab1402d619 (patch) | |
tree | 4679cbb2d52918ca61f873af7711121264864e4c /llvm/lib/Support/ErrorHandling.cpp | |
parent | 1284dc34abd11ce4275ad21c0470ad8c679b59b7 (diff) | |
download | llvm-848b0e244c9ff5413c2eee6357d5faab1402d619.zip llvm-848b0e244c9ff5413c2eee6357d5faab1402d619.tar.gz llvm-848b0e244c9ff5413c2eee6357d5faab1402d619.tar.bz2 |
Improve error handling for SmallVector programming errors
This patch changes errors in `SmallVector::grow` that are independent of
memory capacity to be reported using report_fatal_error or
std::length_error instead of report_bad_alloc_error, which falsely signals
an OOM.
It also cleans up a few related things:
- makes report_bad_alloc_error to print the failure reason passed
to it.
- fixes the documentation to indicate that report_bad_alloc_error
calls `abort()` not "an assertion"
- uses a consistent name for the size/capacity argument to `grow`
and `grow_pod`
Reviewed By: mehdi_amini, MaskRay
Differential Revision: https://reviews.llvm.org/D86892
Diffstat (limited to 'llvm/lib/Support/ErrorHandling.cpp')
-rw-r--r-- | llvm/lib/Support/ErrorHandling.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp index e962657..23b9f96 100644 --- a/llvm/lib/Support/ErrorHandling.cpp +++ b/llvm/lib/Support/ErrorHandling.cpp @@ -168,9 +168,11 @@ void llvm::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) { #else // Don't call the normal error handler. It may allocate memory. Directly write // an OOM to stderr and abort. - char OOMMessage[] = "LLVM ERROR: out of memory\n"; - ssize_t written = ::write(2, OOMMessage, strlen(OOMMessage)); - (void)written; + const char *OOMMessage = "LLVM ERROR: out of memory\n"; + const char *Newline = "\n"; + (void)::write(2, OOMMessage, strlen(OOMMessage)); + (void)::write(2, Reason, strlen(Reason)); + (void)::write(2, Newline, strlen(Newline)); abort(); #endif } |