Aaron Ballman | 68fcfa1 | 2014-09-11 17:26:43 +0000 | [diff] [blame] | 1 | //===-------------------------- test_aux_runtime_op_array_new.cpp ---------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Asiri Rathnayake | 4174e8b | 2016-05-31 12:01:32 +0000 | [diff] [blame] | 10 | // UNSUPPORTED: libcxxabi-no-exceptions |
| 11 | |
Aaron Ballman | 68fcfa1 | 2014-09-11 17:26:43 +0000 | [diff] [blame] | 12 | #include <iostream> |
| 13 | #include <cxxabi.h> |
| 14 | |
| 15 | // If the expression passed to operator new[] would result in an overflow, the |
| 16 | // allocation function is not called, and a std::bad_array_new_length exception |
| 17 | // is thrown instead (5.3.4p7). |
| 18 | bool bad_array_new_length_test() { |
| 19 | try { |
| 20 | // We test this directly because Clang does not currently codegen the |
| 21 | // correct call to __cxa_bad_array_new_length, so this test would result |
| 22 | // in passing -1 to ::operator new[], which would then throw a |
| 23 | // std::bad_alloc, causing the test to fail. |
| 24 | __cxxabiv1::__cxa_throw_bad_array_new_length(); |
| 25 | } catch ( const std::bad_array_new_length &banl ) { |
| 26 | return true; |
| 27 | } |
| 28 | return false; |
| 29 | } |
| 30 | |
Eric Fiselier | 08bf03c | 2016-12-24 00:37:13 +0000 | [diff] [blame] | 31 | int main() { |
Aaron Ballman | 68fcfa1 | 2014-09-11 17:26:43 +0000 | [diff] [blame] | 32 | int ret_val = 0; |
| 33 | |
| 34 | if ( !bad_array_new_length_test ()) { |
| 35 | std::cerr << "Bad array new length test failed!" << std::endl; |
| 36 | ret_val = 1; |
| 37 | } |
| 38 | |
| 39 | return ret_val; |
| 40 | } |