diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/InterferenceCache.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/CodeGen/LiveIntervalUnion.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/CodeGen/RegisterPressure.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/ExecutionEngine/Interpreter/Execution.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Object/Object.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Support/ErrorHandling.cpp | 33 | ||||
-rw-r--r-- | llvm/lib/Support/FoldingSet.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Support/RWMutex.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Support/StringMap.cpp | 13 | ||||
-rw-r--r-- | llvm/lib/Support/Unix/Signals.inc | 2 | ||||
-rw-r--r-- | llvm/lib/Support/Windows/RWMutex.inc | 4 |
11 files changed, 52 insertions, 19 deletions
diff --git a/llvm/lib/CodeGen/InterferenceCache.cpp b/llvm/lib/CodeGen/InterferenceCache.cpp index 72227cc7bba..2bc56c509b9 100644 --- a/llvm/lib/CodeGen/InterferenceCache.cpp +++ b/llvm/lib/CodeGen/InterferenceCache.cpp @@ -48,8 +48,8 @@ void InterferenceCache::reinitPhysRegEntries() { if (PhysRegEntriesCount == TRI->getNumRegs()) return; free(PhysRegEntries); PhysRegEntriesCount = TRI->getNumRegs(); - PhysRegEntries = (unsigned char*) - calloc(PhysRegEntriesCount, sizeof(unsigned char)); + PhysRegEntries = static_cast<unsigned char*>( + llvm::calloc(PhysRegEntriesCount, sizeof(unsigned char))); } void InterferenceCache::init(MachineFunction *mf, diff --git a/llvm/lib/CodeGen/LiveIntervalUnion.cpp b/llvm/lib/CodeGen/LiveIntervalUnion.cpp index 3e742a6c2f2..84b3294fbb8 100644 --- a/llvm/lib/CodeGen/LiveIntervalUnion.cpp +++ b/llvm/lib/CodeGen/LiveIntervalUnion.cpp @@ -187,7 +187,7 @@ void LiveIntervalUnion::Array::init(LiveIntervalUnion::Allocator &Alloc, clear(); Size = NSize; LIUs = static_cast<LiveIntervalUnion*>( - malloc(sizeof(LiveIntervalUnion)*NSize)); + llvm::malloc(sizeof(LiveIntervalUnion)*NSize)); for (unsigned i = 0; i != Size; ++i) new(LIUs + i) LiveIntervalUnion(Alloc); } diff --git a/llvm/lib/CodeGen/RegisterPressure.cpp b/llvm/lib/CodeGen/RegisterPressure.cpp index bc1af1594c2..9f8c7288e25 100644 --- a/llvm/lib/CodeGen/RegisterPressure.cpp +++ b/llvm/lib/CodeGen/RegisterPressure.cpp @@ -635,7 +635,8 @@ void PressureDiffs::init(unsigned N) { } Max = Size; free(PDiffArray); - PDiffArray = reinterpret_cast<PressureDiff*>(calloc(N, sizeof(PressureDiff))); + PDiffArray = static_cast<PressureDiff*>( + llvm::calloc(N, sizeof(PressureDiff))); } void PressureDiffs::addInstruction(unsigned Idx, diff --git a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp index 96844439e72..f641f5023bc 100644 --- a/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/llvm/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -974,7 +974,7 @@ void Interpreter::visitAllocaInst(AllocaInst &I) { unsigned MemToAlloc = std::max(1U, NumElements * TypeSize); // Allocate enough memory to hold the type... - void *Memory = malloc(MemToAlloc); + void *Memory = llvm::malloc(MemToAlloc); DEBUG(dbgs() << "Allocated Type: " << *Ty << " (" << TypeSize << " bytes) x " << NumElements << " (Total: " << MemToAlloc << ") at " diff --git a/llvm/lib/Object/Object.cpp b/llvm/lib/Object/Object.cpp index 1d2859cfbe9..8ba093bf224 100644 --- a/llvm/lib/Object/Object.cpp +++ b/llvm/lib/Object/Object.cpp @@ -228,7 +228,7 @@ uint64_t LLVMGetRelocationType(LLVMRelocationIteratorRef RI) { const char *LLVMGetRelocationTypeName(LLVMRelocationIteratorRef RI) { SmallVector<char, 0> ret; (*unwrap(RI))->getTypeName(ret); - char *str = static_cast<char*>(malloc(ret.size())); + char *str = static_cast<char*>(llvm::malloc(ret.size())); std::copy(ret.begin(), ret.end(), str); return str; } diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp index fb8ae4c1cd5..cb14749cc42 100644 --- a/llvm/lib/Support/ErrorHandling.cpp +++ b/llvm/lib/Support/ErrorHandling.cpp @@ -175,6 +175,39 @@ void llvm::report_bad_alloc_error(const char *Reason, bool GenCrashDiag) { #endif } +#ifdef LLVM_ENABLE_EXCEPTIONS +// Do not set custom new handler if exceptions are enabled. In this case OOM +// errors are handled by throwing 'std::bad_alloc'. +void llvm::install_out_of_memory_new_handler() { +} +#else +// Causes crash on allocation failure. It is called prior to the handler set by +// 'install_bad_alloc_error_handler'. +static void out_of_memory_new_handler() { + llvm::report_bad_alloc_error("Allocation failed"); +} + +// Installs new handler that causes crash on allocation failure. It does not +// need to be called explicitly, if this file is linked to application, because +// in this case it is called during construction of 'new_handler_installer'. +void llvm::install_out_of_memory_new_handler() { + static bool out_of_memory_new_handler_installed = false; + if (!out_of_memory_new_handler_installed) { + std::set_new_handler(out_of_memory_new_handler); + out_of_memory_new_handler_installed = true; + } +} + +// Static object that causes installation of 'out_of_memory_new_handler' before +// execution of 'main'. +static class NewHandlerInstaller { +public: + NewHandlerInstaller() { + install_out_of_memory_new_handler(); + } +} new_handler_installer; +#endif + void llvm::llvm_unreachable_internal(const char *msg, const char *file, unsigned line) { // This code intentionally doesn't call the ErrorHandler callback, because diff --git a/llvm/lib/Support/FoldingSet.cpp b/llvm/lib/Support/FoldingSet.cpp index 94237954903..7b1da136b9b 100644 --- a/llvm/lib/Support/FoldingSet.cpp +++ b/llvm/lib/Support/FoldingSet.cpp @@ -214,7 +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*))); + void **Buckets = static_cast<void**>( + llvm::calloc(NumBuckets+1, sizeof(void*))); if (Buckets == nullptr) report_bad_alloc_error("Allocation of Buckets failed."); diff --git a/llvm/lib/Support/RWMutex.cpp b/llvm/lib/Support/RWMutex.cpp index 83c6d1d52b4..48866e336b5 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*>(llvm::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..4a985b06838 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)); - + StringMapEntryBase **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..12b84fa4861 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 *>(llvm::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..6f99f591322 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_ = llvm::calloc(1, sizeof(SRWLOCK)); fpInitializeSRWLock(static_cast<PSRWLOCK>(data_)); } else { - data_ = calloc(1, sizeof(CRITICAL_SECTION)); + data_ = llvm::calloc(1, sizeof(CRITICAL_SECTION)); InitializeCriticalSection(static_cast<LPCRITICAL_SECTION>(data_)); } } |