1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "__cxxabi_config.h"
10#include "abort_message.h"
11#include <new>
12
13// Perform a few sanity checks on libc++ and libc++abi macros to ensure that
14// the code below can be an exact copy of the code in libcxx/src/new.cpp.
15#if !defined(_THROW_BAD_ALLOC)
16# error The _THROW_BAD_ALLOC macro should be already defined by libc++
17#endif
18
19#if defined(_LIBCXXABI_NO_EXCEPTIONS) != !_LIBCPP_HAS_EXCEPTIONS
20# error libc++ and libc++abi seem to disagree on whether exceptions are enabled
21#endif
22
23inline void __throw_bad_alloc_shim() {
24#if _LIBCPP_HAS_EXCEPTIONS
25 throw std::bad_alloc();
26#else
27 __abort_message("bad_alloc was thrown in -fno-exceptions mode");
28#endif
29}
30
31#define _LIBCPP_ASSERT_SHIM(expr, str) \
32 do { \
33 if (!expr) \
34 __abort_message(str); \
35 } while (false)
36
37#include "support/new.ipp"
38