diff --git a/libcxxabi/CREDITS.TXT b/libcxxabi/CREDITS.TXT index 6e491c58b3ea..9c910fcfd0ca 100644 --- a/libcxxabi/CREDITS.TXT +++ b/libcxxabi/CREDITS.TXT @@ -8,6 +8,10 @@ beautification by scripts. The fields are: name (N), email (E), web-address (W), PGP key ID and fingerprint (P), description (D), and snail-mail address (S). +N: Aaron Ballman +E: aaron@aaronballman.com +D: Minor patches + N: Logan Chien E: logan.chien@mediatek.com D: ARM EHABI Unwind & Exception Handling diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h index 867ba72940fa..46d673008b7a 100644 --- a/libcxxabi/include/cxxabi.h +++ b/libcxxabi/include/cxxabi.h @@ -66,6 +66,7 @@ extern LIBCXXABI_NORETURN void __cxa_rethrow(); // 2.6 Auxiliary Runtime APIs extern LIBCXXABI_NORETURN void __cxa_bad_cast(void); extern LIBCXXABI_NORETURN void __cxa_bad_typeid(void); +extern LIBCXXABI_NORETURN void __cxa_throw_bad_array_new_length(void); diff --git a/libcxxabi/src/cxa_aux_runtime.cpp b/libcxxabi/src/cxa_aux_runtime.cpp index 15fede04eced..7fec810fb731 100644 --- a/libcxxabi/src/cxa_aux_runtime.cpp +++ b/libcxxabi/src/cxa_aux_runtime.cpp @@ -11,6 +11,7 @@ //===----------------------------------------------------------------------===// #include "cxxabi.h" +#include #include namespace __cxxabiv1 @@ -29,6 +30,10 @@ void __cxa_bad_typeid(void) { throw std::bad_typeid(); } +LIBCXXABI_NORETURN +void __cxa_throw_bad_array_new_length(void) { + throw std::bad_array_new_length(); +} } // extern "C" } // abi diff --git a/libcxxabi/test/test_aux_runtime_op_array_new.cpp b/libcxxabi/test/test_aux_runtime_op_array_new.cpp new file mode 100644 index 000000000000..8d9f547a3151 --- /dev/null +++ b/libcxxabi/test/test_aux_runtime_op_array_new.cpp @@ -0,0 +1,38 @@ +//===-------------------------- test_aux_runtime_op_array_new.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 +#include + +// If the expression passed to operator new[] would result in an overflow, the +// allocation function is not called, and a std::bad_array_new_length exception +// is thrown instead (5.3.4p7). +bool bad_array_new_length_test() { + try { + // We test this directly because Clang does not currently codegen the + // correct call to __cxa_bad_array_new_length, so this test would result + // in passing -1 to ::operator new[], which would then throw a + // std::bad_alloc, causing the test to fail. + __cxxabiv1::__cxa_throw_bad_array_new_length(); + } catch ( const std::bad_array_new_length &banl ) { + return true; + } + return false; +} + +int main(int argc, char *argv []) { + int ret_val = 0; + + if ( !bad_array_new_length_test ()) { + std::cerr << "Bad array new length test failed!" << std::endl; + ret_val = 1; + } + + return ret_val; +}