summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/DataLayout.cpp
diff options
context:
space:
mode:
authorSerge Pavlov <sepavloff@gmail.com>2018-06-09 05:19:45 +0000
committerSerge Pavlov <sepavloff@gmail.com>2018-06-09 05:19:45 +0000
commit15681ad00b83c606dbb13af8782610a61bf39687 (patch)
treeb3d4599dbf9dd2a083456965ddaa085b17f8ccd1 /llvm/lib/IR/DataLayout.cpp
parent61998289f93772f354a29417ce76323b13bd4736 (diff)
downloadbcm5719-llvm-15681ad00b83c606dbb13af8782610a61bf39687.tar.gz
bcm5719-llvm-15681ad00b83c606dbb13af8782610a61bf39687.zip
Use uniform mechanism for OOM errors handling
This is a recommit of r333506, which was reverted in r333518. The original commit message is below. In r325551 many calls of malloc/calloc/realloc were replaces with calls of their safe counterparts defined in the namespace llvm. There functions generate crash if memory cannot be allocated, such behavior facilitates handling of out of memory errors on Windows. If the result of *alloc function were checked for success, the function was not replaced with the safe variant. In these cases the calling function made the error handling, like: T *NewElts = static_cast<T*>(malloc(NewCapacity*sizeof(T))); if (NewElts == nullptr) report_bad_alloc_error("Allocation of SmallVector element failed."); Actually knowledge about the function where OOM occurred is useless. Moreover having a single entry point for OOM handling is convenient for investigation of memory problems. This change removes custom OOM errors handling and replaces them with calls to functions `llvm::safe_*alloc`. Declarations of `safe_*alloc` are moved to a separate include file, to avoid cyclic dependency in SmallVector.h Differential Revision: https://reviews.llvm.org/D47440 llvm-svn: 334344
Diffstat (limited to 'llvm/lib/IR/DataLayout.cpp')
-rw-r--r--llvm/lib/IR/DataLayout.cpp6
1 files changed, 2 insertions, 4 deletions
diff --git a/llvm/lib/IR/DataLayout.cpp b/llvm/lib/IR/DataLayout.cpp
index fff2f67fe5a..62c67127276 100644
--- a/llvm/lib/IR/DataLayout.cpp
+++ b/llvm/lib/IR/DataLayout.cpp
@@ -596,10 +596,8 @@ const StructLayout *DataLayout::getStructLayout(StructType *Ty) const {
// Otherwise, create the struct layout. Because it is variable length, we
// malloc it, then use placement new.
int NumElts = Ty->getNumElements();
- StructLayout *L =
- (StructLayout *)malloc(sizeof(StructLayout)+(NumElts-1) * sizeof(uint64_t));
- if (L == nullptr)
- report_bad_alloc_error("Allocation of StructLayout elements failed.");
+ StructLayout *L = (StructLayout *)
+ safe_malloc(sizeof(StructLayout)+(NumElts-1) * sizeof(uint64_t));
// Set SL before calling StructLayout's ctor. The ctor could cause other
// entries to be added to TheMap, invalidating our reference.
OpenPOWER on IntegriCloud