summaryrefslogtreecommitdiff
path: root/contrib/llvm/lib/Support/SmallPtrSet.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-12-20 14:16:56 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-12-20 14:16:56 +0000
commit2cab237b5dbfe1b3e9c7aa7a3c02d2b98fcf7462 (patch)
tree524fe828571f81358bba62fdb6d04c6e5e96a2a4 /contrib/llvm/lib/Support/SmallPtrSet.cpp
parent6c7828a2807ea5e50c79ca42dbedf2b589ce63b2 (diff)
parent044eb2f6afba375a914ac9d8024f8f5142bb912e (diff)
Notes
Diffstat (limited to 'contrib/llvm/lib/Support/SmallPtrSet.cpp')
-rw-r--r--contrib/llvm/lib/Support/SmallPtrSet.cpp20
1 files changed, 15 insertions, 5 deletions
diff --git a/contrib/llvm/lib/Support/SmallPtrSet.cpp b/contrib/llvm/lib/Support/SmallPtrSet.cpp
index aa12e85fa4c0..119bb871d4c0 100644
--- a/contrib/llvm/lib/Support/SmallPtrSet.cpp
+++ b/contrib/llvm/lib/Support/SmallPtrSet.cpp
@@ -15,6 +15,7 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/Support/MathExtras.h"
+#include "llvm/Support/ErrorHandling.h"
#include <algorithm>
#include <cassert>
#include <cstdlib>
@@ -32,7 +33,9 @@ void SmallPtrSetImplBase::shrink_and_clear() {
// Install the new array. Clear all the buckets to empty.
CurArray = (const void**)malloc(sizeof(void*) * CurArraySize);
- assert(CurArray && "Failed to allocate memory?");
+ if (CurArray == nullptr)
+ report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed.");
+
memset(CurArray, -1, CurArraySize*sizeof(void*));
}
@@ -58,6 +61,7 @@ SmallPtrSetImplBase::insert_imp_big(const void *Ptr) {
else
++NumNonEmpty; // Track density.
*Bucket = Ptr;
+ incrementEpoch();
return std::make_pair(Bucket, true);
}
@@ -96,8 +100,12 @@ void SmallPtrSetImplBase::Grow(unsigned NewSize) {
bool WasSmall = isSmall();
// Install the new array. Clear all the buckets to empty.
- CurArray = (const void**)malloc(sizeof(void*) * NewSize);
- assert(CurArray && "Failed to allocate memory?");
+ const void **NewBuckets = (const void**) malloc(sizeof(void*) * NewSize);
+ if (NewBuckets == nullptr)
+ report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed.");
+
+ // Reset member only if memory was allocated successfully
+ CurArray = NewBuckets;
CurArraySize = NewSize;
memset(CurArray, -1, NewSize*sizeof(void*));
@@ -125,7 +133,8 @@ SmallPtrSetImplBase::SmallPtrSetImplBase(const void **SmallStorage,
// Otherwise, allocate new heap space (unless we were the same size)
} else {
CurArray = (const void**)malloc(sizeof(void*) * that.CurArraySize);
- assert(CurArray && "Failed to allocate memory?");
+ if (CurArray == nullptr)
+ report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed.");
}
// Copy over the that array.
@@ -162,7 +171,8 @@ void SmallPtrSetImplBase::CopyFrom(const SmallPtrSetImplBase &RHS) {
free(CurArray);
CurArray = T;
}
- assert(CurArray && "Failed to allocate memory?");
+ if (CurArray == nullptr)
+ report_bad_alloc_error("Allocation of SmallPtrSet bucket array failed.");
}
CopyHelper(RHS);