[debug] Use poison instead of undef to set a killed dbg.assign address [NFC] (#119760)
[llvm-project.git] / libcxx / include / __cxx03 / __memory / builtin_new_allocator.h
blobe14a57e8a0611c0ec0bcfb7b078180678347e585
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 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___CXX03___MEMORY_BUILTIN_NEW_ALLOCATOR_H
10 #define _LIBCPP___CXX03___MEMORY_BUILTIN_NEW_ALLOCATOR_H
12 #include <__cxx03/__config>
13 #include <__cxx03/__memory/unique_ptr.h>
14 #include <__cxx03/cstddef>
15 #include <__cxx03/new>
17 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
18 # pragma GCC system_header
19 #endif
21 _LIBCPP_BEGIN_NAMESPACE_STD
23 // __builtin_new_allocator -- A non-templated helper for allocating and
24 // deallocating memory using __builtin_operator_new and
25 // __builtin_operator_delete. It should be used in preference to
26 // `std::allocator<T>` to avoid additional instantiations.
27 struct __builtin_new_allocator {
28 struct __builtin_new_deleter {
29 typedef void* pointer_type;
31 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align)
32 : __size_(__size), __align_(__align) {}
34 _LIBCPP_HIDE_FROM_ABI void operator()(void* __p) const _NOEXCEPT {
35 std::__libcpp_deallocate(__p, __size_, __align_);
38 private:
39 size_t __size_;
40 size_t __align_;
43 typedef unique_ptr<void, __builtin_new_deleter> __holder_t;
45 _LIBCPP_HIDE_FROM_ABI static __holder_t __allocate_bytes(size_t __s, size_t __align) {
46 return __holder_t(std::__libcpp_allocate(__s, __align), __builtin_new_deleter(__s, __align));
49 _LIBCPP_HIDE_FROM_ABI static void __deallocate_bytes(void* __p, size_t __s, size_t __align) _NOEXCEPT {
50 std::__libcpp_deallocate(__p, __s, __align);
53 template <class _Tp>
54 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI static __holder_t __allocate_type(size_t __n) {
55 return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
58 template <class _Tp>
59 _LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE _LIBCPP_HIDE_FROM_ABI static void
60 __deallocate_type(void* __p, size_t __n) _NOEXCEPT {
61 __deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
65 _LIBCPP_END_NAMESPACE_STD
67 #endif // _LIBCPP___CXX03___MEMORY_BUILTIN_NEW_ALLOCATOR_H