[PATCH] D77601: Make SmallVector assert if it cannot grow.
Andrew via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 7 13:03:56 PDT 2020
browneee updated this revision to Diff 255777.
browneee added a comment.
Add "report a " to comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77601/new/
https://reviews.llvm.org/D77601
Files:
llvm/include/llvm/ADT/SmallVector.h
llvm/lib/Support/SmallVector.cpp
Index: llvm/lib/Support/SmallVector.cpp
===================================================================
--- llvm/lib/Support/SmallVector.cpp
+++ llvm/lib/Support/SmallVector.cpp
@@ -39,12 +39,19 @@
/// grow_pod - This is an implementation of the grow() method which only works
/// on POD-like datatypes and is out of line to reduce code duplication.
+/// This function will report a fatal error if it cannot increase capacity.
void SmallVectorBase::grow_pod(void *FirstEl, size_t MinCapacity,
size_t TSize) {
// Ensure we can fit the new capacity in 32 bits.
if (MinCapacity > UINT32_MAX)
report_bad_alloc_error("SmallVector capacity overflow during allocation");
+ // 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.
+ if (capacity() == size_t(UINT32_MAX))
+ report_bad_alloc_error("SmallVector capacity unable to grow");
+
size_t NewCapacity = 2 * capacity() + 1; // Always grow.
NewCapacity =
std::min(std::max(NewCapacity, MinCapacity), size_t(UINT32_MAX));
Index: llvm/include/llvm/ADT/SmallVector.h
===================================================================
--- llvm/include/llvm/ADT/SmallVector.h
+++ llvm/include/llvm/ADT/SmallVector.h
@@ -46,6 +46,7 @@
/// This is an implementation of the grow() method which only works
/// on POD-like data types and is out of line to reduce code duplication.
+ /// This function will report a fatal error if it cannot increase capacity.
void grow_pod(void *FirstEl, size_t MinCapacity, size_t TSize);
public:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77601.255777.patch
Type: text/x-patch
Size: 1732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200407/2dae858f/attachment-0001.bin>
More information about the llvm-commits
mailing list