diff options
author | Serge Pavlov <sepavloff@gmail.com> | 2018-05-29 05:39:08 +0000 |
---|---|---|
committer | Serge Pavlov <sepavloff@gmail.com> | 2018-05-29 05:39:08 +0000 |
commit | 0e31285fe88dbe817932fc9a96d13b84e59b55ce (patch) | |
tree | 40f0addd85bc8d000b1ecb25cab673e24781b380 /llvm/lib/Support/FoldingSet.cpp | |
parent | 74d6a7400cd2ec277b7d90ca56a31eea21ae0e48 (diff) | |
download | bcm5719-llvm-0e31285fe88dbe817932fc9a96d13b84e59b55ce.tar.gz bcm5719-llvm-0e31285fe88dbe817932fc9a96d13b84e59b55ce.zip |
Use uniform mechanism for OOM errors handling
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: 333390
Diffstat (limited to 'llvm/lib/Support/FoldingSet.cpp')
-rw-r--r-- | llvm/lib/Support/FoldingSet.cpp | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/llvm/lib/Support/FoldingSet.cpp b/llvm/lib/Support/FoldingSet.cpp index 94237954903..ec7d57586e8 100644 --- a/llvm/lib/Support/FoldingSet.cpp +++ b/llvm/lib/Support/FoldingSet.cpp @@ -214,11 +214,8 @@ static void **GetBucketFor(unsigned Hash, void **Buckets, unsigned NumBuckets) { /// AllocateBuckets - Allocated initialized bucket memory. static void **AllocateBuckets(unsigned NumBuckets) { - void **Buckets = static_cast<void**>(calloc(NumBuckets+1, sizeof(void*))); - - if (Buckets == nullptr) - report_bad_alloc_error("Allocation of Buckets failed."); - + void **Buckets = static_cast<void**>(safe_calloc(NumBuckets + 1, + sizeof(void*))); // Set the very last bucket to be a non-null "pointer". Buckets[NumBuckets] = reinterpret_cast<void*>(-1); return Buckets; |