[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

llvm-svn: 239392
This commit is contained in:
Daniel Sanders 2015-06-09 09:47:46 +00:00
parent 4582c79879
commit a2fe278290

View File

@ -33,6 +33,7 @@ void SmallVectorBase::grow_pod(void *FirstEl, size_t MinSizeInBytes,
// If this wasn't grown from the inline copy, grow the allocated space. // If this wasn't grown from the inline copy, grow the allocated space.
NewElts = realloc(this->BeginX, NewCapacityInBytes); NewElts = realloc(this->BeginX, NewCapacityInBytes);
} }
assert(NewElts && "Out of memory");
this->EndX = (char*)NewElts+CurSizeBytes; this->EndX = (char*)NewElts+CurSizeBytes;
this->BeginX = NewElts; this->BeginX = NewElts;