[llvm] r239392 - [ADT] Assert that SmallVectorBase::grow_pod() successfully reallocates memory.

Daniel Sanders daniel.sanders at imgtec.com
Tue Jun 9 02:47:46 PDT 2015


Author: dsanders
Date: Tue Jun  9 04:47:46 2015
New Revision: 239392

URL: http://llvm.org/viewvc/llvm-project?rev=239392&view=rev
Log:
[ADT] Assert that SmallVectorBase::grow_pod() successfully reallocates memory.

Summary:
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.

Reviewers: bkramer

Reviewed By: bkramer

Subscribers: bkramer, llvm-commits

Differential Revision: http://reviews.llvm.org/D9520

Modified:
    llvm/trunk/lib/Support/SmallVector.cpp

Modified: llvm/trunk/lib/Support/SmallVector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/SmallVector.cpp?rev=239392&r1=239391&r2=239392&view=diff
==============================================================================
--- llvm/trunk/lib/Support/SmallVector.cpp (original)
+++ llvm/trunk/lib/Support/SmallVector.cpp Tue Jun  9 04:47:46 2015
@@ -33,6 +33,7 @@ void SmallVectorBase::grow_pod(void *Fir
     // 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;





More information about the llvm-commits mailing list