|
|
|||
File indexing completed on 2026-05-03 08:13:56
0001 // -*- C++ -*- 0002 //===----------------------------------------------------------------------===// 0003 // 0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0005 // See https://llvm.org/LICENSE.txt for license information. 0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0007 // 0008 //===----------------------------------------------------------------------===// 0009 0010 #ifndef _LIBCPP___MEMORY_ARRAY_COOKIE_H 0011 #define _LIBCPP___MEMORY_ARRAY_COOKIE_H 0012 0013 #include <__config> 0014 #include <__configuration/abi.h> 0015 #include <__cstddef/size_t.h> 0016 #include <__type_traits/integral_constant.h> 0017 #include <__type_traits/is_trivially_destructible.h> 0018 #include <__type_traits/negation.h> 0019 0020 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 0021 # pragma GCC system_header 0022 #endif 0023 0024 _LIBCPP_BEGIN_NAMESPACE_STD 0025 0026 // Trait representing whether a type requires an array cookie at the start of its allocation when 0027 // allocated as `new T[n]` and deallocated as `delete[] array`. 0028 // 0029 // Under the Itanium C++ ABI [1], we know that an array cookie is available unless `T` is trivially 0030 // destructible and the call to `operator delete[]` is not a sized operator delete. Under ABIs other 0031 // than the Itanium ABI, we assume there are no array cookies. 0032 // 0033 // [1]: https://itanium-cxx-abi.github.io/cxx-abi/abi.html#array-cookies 0034 #ifdef _LIBCPP_ABI_ITANIUM 0035 // TODO: Use a builtin instead 0036 // TODO: We should factor in the choice of the usual deallocation function in this determination. 0037 template <class _Tp> 0038 struct __has_array_cookie : _Not<is_trivially_destructible<_Tp> > {}; 0039 #else 0040 template <class _Tp> 0041 struct __has_array_cookie : false_type {}; 0042 #endif 0043 0044 template <class _Tp> 0045 // Avoid failures when -fsanitize-address-poison-custom-array-cookie is enabled 0046 _LIBCPP_HIDE_FROM_ABI _LIBCPP_NO_SANITIZE("address") size_t __get_array_cookie(_Tp const* __ptr) { 0047 static_assert( 0048 __has_array_cookie<_Tp>::value, "Trying to access the array cookie of a type that is not guaranteed to have one"); 0049 size_t const* __cookie = reinterpret_cast<size_t const*>(__ptr) - 1; // TODO: Use a builtin instead 0050 return *__cookie; 0051 } 0052 0053 _LIBCPP_END_NAMESPACE_STD 0054 0055 #endif // _LIBCPP___MEMORY_ARRAY_COOKIE_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|