summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/RWMutex.cpp3
-rw-r--r--llvm/lib/Support/StringMap.cpp13
-rw-r--r--llvm/lib/Support/Unix/Signals.inc2
-rw-r--r--llvm/lib/Support/Windows/RWMutex.inc4
4 files changed, 10 insertions, 12 deletions
diff --git a/llvm/lib/Support/RWMutex.cpp b/llvm/lib/Support/RWMutex.cpp
index 83c6d1d52b4..8182319541e 100644
--- a/llvm/lib/Support/RWMutex.cpp
+++ b/llvm/lib/Support/RWMutex.cpp
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Support/Allocator.h"
#include "llvm/Support/RWMutex.h"
#include "llvm/Config/config.h"
@@ -49,7 +50,7 @@ RWMutexImpl::RWMutexImpl()
{
// Declare the pthread_rwlock data structures
pthread_rwlock_t* rwlock =
- static_cast<pthread_rwlock_t*>(malloc(sizeof(pthread_rwlock_t)));
+ static_cast<pthread_rwlock_t*>(safe_malloc(sizeof(pthread_rwlock_t)));
#ifdef __APPLE__
// Workaround a bug/mis-feature in Darwin's pthread_rwlock_init.
diff --git a/llvm/lib/Support/StringMap.cpp b/llvm/lib/Support/StringMap.cpp
index 4341da2d97b..9382c3ce29e 100644
--- a/llvm/lib/Support/StringMap.cpp
+++ b/llvm/lib/Support/StringMap.cpp
@@ -57,10 +57,9 @@ void StringMapImpl::init(unsigned InitSize) {
NumItems = 0;
NumTombstones = 0;
- TheTable = (StringMapEntryBase **)calloc(NewNumBuckets+1,
- sizeof(StringMapEntryBase **) +
- sizeof(unsigned));
-
+ TheTable = static_cast<StringMapEntryBase **>(
+ std::calloc(NewNumBuckets+1,
+ sizeof(StringMapEntryBase **) + sizeof(unsigned)));
if (TheTable == nullptr)
report_bad_alloc_error("Allocation of StringMap table failed.");
@@ -219,10 +218,8 @@ unsigned StringMapImpl::RehashTable(unsigned BucketNo) {
unsigned NewBucketNo = BucketNo;
// Allocate one extra bucket which will always be non-empty. This allows the
// iterators to stop at end.
- StringMapEntryBase **NewTableArray =
- (StringMapEntryBase **)calloc(NewSize+1, sizeof(StringMapEntryBase *) +
- sizeof(unsigned));
-
+ auto NewTableArray = static_cast<StringMapEntryBase **>(
+ std::calloc(NewSize+1, sizeof(StringMapEntryBase *) + sizeof(unsigned)));
if (NewTableArray == nullptr)
report_bad_alloc_error("Allocation of StringMap hash table failed.");
diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index aaf760c5b61..a626b251ccd 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -138,7 +138,7 @@ static void CreateSigAltStack() {
return;
stack_t AltStack = {};
- AltStack.ss_sp = reinterpret_cast<char *>(malloc(AltStackSize));
+ AltStack.ss_sp = static_cast<char *>(safe_malloc(AltStackSize));
NewAltStackPointer = AltStack.ss_sp; // Save to avoid reporting a leak.
AltStack.ss_size = AltStackSize;
if (sigaltstack(&AltStack, &OldAltStack) != 0)
diff --git a/llvm/lib/Support/Windows/RWMutex.inc b/llvm/lib/Support/Windows/RWMutex.inc
index ac60c2fc05b..5eb9351eee5 100644
--- a/llvm/lib/Support/Windows/RWMutex.inc
+++ b/llvm/lib/Support/Windows/RWMutex.inc
@@ -74,10 +74,10 @@ static bool loadSRW() {
sys::RWMutexImpl::RWMutexImpl() {
if (loadSRW()) {
- data_ = calloc(1, sizeof(SRWLOCK));
+ data_ = safe_calloc(1, sizeof(SRWLOCK));
fpInitializeSRWLock(static_cast<PSRWLOCK>(data_));
} else {
- data_ = calloc(1, sizeof(CRITICAL_SECTION));
+ data_ = safe_calloc(1, sizeof(CRITICAL_SECTION));
InitializeCriticalSection(static_cast<LPCRITICAL_SECTION>(data_));
}
}
OpenPOWER on IntegriCloud