summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Support/AllocatorTest.cpp
diff options
context:
space:
mode:
authorSerge Pavlov <sepavloff@gmail.com>2018-02-15 09:20:26 +0000
committerSerge Pavlov <sepavloff@gmail.com>2018-02-15 09:20:26 +0000
commit431502a675edc407791fecde0cf96b0d658b789a (patch)
tree48492d407fa621e3d386e3473bc62778fe4bf6a7 /llvm/unittests/Support/AllocatorTest.cpp
parenta06d0802049d01f2ba1197a492fcc6836cdd1a60 (diff)
downloadbcm5719-llvm-431502a675edc407791fecde0cf96b0d658b789a.tar.gz
bcm5719-llvm-431502a675edc407791fecde0cf96b0d658b789a.zip
Report fatal error in the case of out of memory
Analysis of fails in the case of out of memory errors can be tricky on Windows. Such error emerges at the point where memory allocation function fails, but manifests itself when null pointer is used. These two points may be distant from each other. Besides, next runs may not exhibit allocation error. Usual programming practice does not require checking result of 'operator new' because it throws 'std::bad_alloc' in the case of allocation error. However, LLVM is usually built with exceptions turned off, so 'new' can return null pointer. This change installs custom new handler, which causes fatal error in the case of out of memory. The handler is installed automatically prior to call to 'main' during construction of a static object defined in 'lib/Support/ErrorHandling.cpp'. If the application does not use this file, the handler may be installed manually by a call to 'llvm::install_out_of_memory_new_handler', declared in 'include/llvm/Support/ErrorHandling.h". There are calls to C allocation functions, malloc, calloc and realloc. They are used for interoperability with C code, when allocated object has variable size and when it is necessary to avoid call of constructors. In many calls the result is not checked against null pointer. To simplify checks, new functions are defined in the namespace 'llvm' with the same names as these C function. These functions produce fatal error if allocation fails. User should use 'llvm::malloc' instead of 'std::malloc' in order to use the safe variant. This change replaces 'std::malloc' in the cases when the result of allocation function is not checked against null pointer. Finally, there are plain C code, that uses malloc and similar functions. If the result is not checked, assert statements are added. Differential Revision: https://reviews.llvm.org/D43010 llvm-svn: 325224
Diffstat (limited to 'llvm/unittests/Support/AllocatorTest.cpp')
-rw-r--r--llvm/unittests/Support/AllocatorTest.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/llvm/unittests/Support/AllocatorTest.cpp b/llvm/unittests/Support/AllocatorTest.cpp
index 4897c47eb28..b26c8a6ec3e 100644
--- a/llvm/unittests/Support/AllocatorTest.cpp
+++ b/llvm/unittests/Support/AllocatorTest.cpp
@@ -147,7 +147,7 @@ public:
// Allocate space for the alignment, the slab, and a void* that goes right
// before the slab.
size_t Alignment = 4096;
- void *MemBase = malloc(Size + Alignment - 1 + sizeof(void*));
+ void *MemBase = llvm::malloc(Size + Alignment - 1 + sizeof(void*));
// Find the slab start.
void *Slab = (void *)alignAddr((char*)MemBase + sizeof(void *), Alignment);
OpenPOWER on IntegriCloud