Skip to content

Commit 3c892ef

Browse files
committed
[LLVMSupport] Simplify error reporting in SmallVector and avoid using std::string when producing fatal errors messages
1 parent d11b8a7 commit 3c892ef

File tree

1 file changed

+2
-32
lines changed

1 file changed

+2
-32
lines changed

stdlib/public/LLVMSupport/SmallVector.cpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,36 +45,6 @@ static_assert(sizeof(SmallVector<char, 0>) ==
4545
sizeof(void *) * 2 + sizeof(void *),
4646
"1 byte elements have word-sized type for size and capacity");
4747

48-
/// Report that MinSize doesn't fit into this vector's size type. Throws
49-
/// std::length_error or calls report_fatal_error.
50-
LLVM_ATTRIBUTE_NORETURN
51-
static void report_size_overflow(size_t MinSize, size_t MaxSize);
52-
static void report_size_overflow(size_t MinSize, size_t MaxSize) {
53-
std::string Reason = "SmallVector unable to grow. Requested capacity (" +
54-
std::to_string(MinSize) +
55-
") is larger than maximum value for size type (" +
56-
std::to_string(MaxSize) + ")";
57-
#ifdef LLVM_ENABLE_EXCEPTIONS
58-
throw std::length_error(Reason);
59-
#else
60-
report_fatal_error(Reason);
61-
#endif
62-
}
63-
64-
/// Report that this vector is already at maximum capacity. Throws
65-
/// std::length_error or calls report_fatal_error.
66-
LLVM_ATTRIBUTE_NORETURN static void report_at_maximum_capacity(size_t MaxSize);
67-
static void report_at_maximum_capacity(size_t MaxSize) {
68-
std::string Reason =
69-
"SmallVector capacity unable to grow. Already at maximum size " +
70-
std::to_string(MaxSize);
71-
#ifdef LLVM_ENABLE_EXCEPTIONS
72-
throw std::length_error(Reason);
73-
#else
74-
report_fatal_error(Reason);
75-
#endif
76-
}
77-
7848
// Note: Moving this function into the header may cause performance regression.
7949
template <class Size_T>
8050
static size_t getNewCapacity(size_t MinSize, size_t TSize, size_t OldCapacity) {
@@ -83,14 +53,14 @@ static size_t getNewCapacity(size_t MinSize, size_t TSize, size_t OldCapacity) {
8353
// Ensure we can fit the new capacity.
8454
// This is only going to be applicable when the capacity is 32 bit.
8555
if (MinSize > MaxSize)
86-
report_size_overflow(MinSize, MaxSize);
56+
report_bad_alloc_error("SmallVector capacity overflow during allocation");
8757

8858
// Ensure we can meet the guarantee of space for at least one more element.
8959
// The above check alone will not catch the case where grow is called with a
9060
// default MinSize of 0, but the current capacity cannot be increased.
9161
// This is only going to be applicable when the capacity is 32 bit.
9262
if (OldCapacity == MaxSize)
93-
report_at_maximum_capacity(MaxSize);
63+
report_bad_alloc_error("SmallVector capacity unable to grow");
9464

9565
// In theory 2*capacity can overflow if the capacity is 64 bit, but the
9666
// original capacity would never be large enough for this to be a problem.

0 commit comments

Comments
 (0)