[PATCH] [ADT] Assert that SmallVectorBase::grow_pod() successfully reallocates memory.

Daniel Sanders daniel.sanders at imgtec.com
Wed May 6 03:55:44 PDT 2015


If malloc/realloc fails then the SmallVector becomes unusable since begin() and
end() will return NULL. This is unlikely to occur but was the cause of recent
bugpoint test failures on my machine.

It is not clear whether not checking for malloc/realloc failure is a deliberate
decision and adding checks has the potential to impact compiler performance.
Therefore, this patch only adds the check to builds with assertions enabled for
the moment.

http://reviews.llvm.org/D9520

Files:
  lib/Support/SmallVector.cpp

Index: lib/Support/SmallVector.cpp
===================================================================
--- lib/Support/SmallVector.cpp
+++ lib/Support/SmallVector.cpp
@@ -33,6 +33,7 @@
     // If this wasn't grown from the inline copy, grow the allocated space.
     NewElts = realloc(this->BeginX, NewCapacityInBytes);
   }
+  assert(NewElts && "Out of memory");
 
   this->EndX = (char*)NewElts+CurSizeBytes;
   this->BeginX = NewElts;

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9520.25030.patch
Type: text/x-patch
Size: 438 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150506/388217eb/attachment.bin>


More information about the llvm-commits mailing list