diff options
Diffstat (limited to 'libcxxabi/test/test_exception_storage_nodynmem.pass.cpp')
-rw-r--r-- | libcxxabi/test/test_exception_storage_nodynmem.pass.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/libcxxabi/test/test_exception_storage_nodynmem.pass.cpp b/libcxxabi/test/test_exception_storage_nodynmem.pass.cpp new file mode 100644 index 00000000000..5c6eeacc628 --- /dev/null +++ b/libcxxabi/test/test_exception_storage_nodynmem.pass.cpp @@ -0,0 +1,32 @@ +//===--------------- test_exception_storage_nodynmem.cpp ------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include <assert.h> +#include <cstdlib> + +static bool OverwrittenCallocCalled = false; + +// Override calloc to simulate exhaustion of dynamic memory +void *calloc(size_t, size_t) { + OverwrittenCallocCalled = true; + return 0; +} + +int main(int argc, char *argv[]) { + // Run the test a couple of times + // to ensure that fallback memory doesn't leak. + for (int I = 0; I < 1000; ++I) + try { + throw 42; + } catch (...) { + } + + assert(OverwrittenCallocCalled); + return 0; +} |