2014-09-12 01:26:43 +08:00
|
|
|
//===-------------------------- test_aux_runtime_op_array_new.cpp ---------===//
|
|
|
|
//
|
2019-01-19 18:56:40 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2014-09-12 01:26:43 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2020-04-17 22:29:15 +08:00
|
|
|
// UNSUPPORTED: no-exceptions
|
2016-05-31 20:01:32 +08:00
|
|
|
|
2014-09-12 01:26:43 +08:00
|
|
|
#include <cxxabi.h>
|
2020-10-14 03:47:31 +08:00
|
|
|
#include <new>
|
2014-09-12 01:26:43 +08:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2020-10-09 01:36:33 +08:00
|
|
|
int main(int, char**) {
|
2014-09-12 01:26:43 +08:00
|
|
|
int ret_val = 0;
|
|
|
|
|
|
|
|
if ( !bad_array_new_length_test ()) {
|
|
|
|
ret_val = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
}
|