diff --git a/llvm/include/llvm/Support/ErrorHandling.h b/llvm/include/llvm/Support/ErrorHandling.h --- a/llvm/include/llvm/Support/ErrorHandling.h +++ b/llvm/include/llvm/Support/ErrorHandling.h @@ -110,9 +110,9 @@ /// the following unwind succeeds, e.g. do not trigger additional allocations /// in the unwind chain. /// -/// If no error handler is installed (default), then a bad_alloc exception -/// is thrown, if LLVM is compiled with exception support, otherwise an -/// assertion is called. +/// If no error handler is installed (default), throws a bad_alloc exception +/// if LLVM is compiled with exception support. Otherwise prints the error +/// to standard error and calls abort(). LLVM_ATTRIBUTE_NORETURN void report_bad_alloc_error(const char *Reason, bool GenCrashDiag = true); diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp --- a/llvm/lib/Support/ErrorHandling.cpp +++ b/llvm/lib/Support/ErrorHandling.cpp @@ -170,6 +170,7 @@ // an OOM to stderr and abort. char OOMMessage[] = "LLVM ERROR: out of memory\n"; ssize_t written = ::write(2, OOMMessage, strlen(OOMMessage)); + written = ::write(2, Reason, strlen(Reason)); (void)written; abort(); #endif diff --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp --- a/llvm/lib/Support/SmallVector.cpp +++ b/llvm/lib/Support/SmallVector.cpp @@ -49,14 +49,19 @@ // Ensure we can fit the new capacity. // This is only going to be applicable when the capacity is 32 bit. if (MinCapacity > SizeTypeMax()) - report_bad_alloc_error("SmallVector capacity overflow during allocation"); + report_fatal_error("SmallVector unable to grow. Requested capacity (" + + std::to_string(MinCapacity) + + ") is larger than maximum capacity for size type (" + + std::to_string(SizeTypeMax()) + ")"); // Ensure we can meet the guarantee of space for at least one more element. // The above check alone will not catch the case where grow is called with a // default MinCapacity of 0, but the current capacity cannot be increased. // This is only going to be applicable when the capacity is 32 bit. if (capacity() == SizeTypeMax()) - report_bad_alloc_error("SmallVector capacity unable to grow"); + report_fatal_error( + "SmallVector capacity unable to grow. Already at maximum size " + + std::to_string(SizeTypeMax())); // In theory 2*capacity can overflow if the capacity is 64 bit, but the // original capacity would never be large enough for this to be a problem.