codekingpro/portable-devtools
114k
1// -*- C++ -*-2//===----------------------------------------------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7// SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES.8//9//===----------------------------------------------------------------------===//10 11#ifndef _LIBCUDACXX___MEMORY_ADDRESSOF_H12#define _LIBCUDACXX___MEMORY_ADDRESSOF_H13 14#ifndef __cuda_std__15#include <__config>16#endif //__cuda_std__17 18#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)19# pragma GCC system_header20#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)21# pragma clang system_header22#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)23# pragma system_header24#endif // no system header25 26_LIBCUDACXX_BEGIN_NAMESPACE_STD27 28// addressof29// NVCXX has the builtin defined but did not mark it as supported30#if defined(_LIBCUDACXX_ADDRESSOF)31 32template <class _Tp>33inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX1134_LIBCUDACXX_NO_CFI _LIBCUDACXX_INLINE_VISIBILITY35_Tp*36addressof(_Tp& __x) noexcept37{38 return __builtin_addressof(__x);39}40 41#else42 43template <class _Tp>44inline _LIBCUDACXX_NO_CFI _LIBCUDACXX_INLINE_VISIBILITY45_Tp*46addressof(_Tp& __x) noexcept47{48 return reinterpret_cast<_Tp *>(49 const_cast<char *>(&reinterpret_cast<const volatile char &>(__x)));50}51 52#endif // defined(_LIBCUDACXX_ADDRESSOF)53 54#if defined(_LIBCUDACXX_HAS_OBJC_ARC) && !defined(_LIBCUDACXX_PREDEFINED_OBJC_ARC_ADDRESSOF)55// Objective-C++ Automatic Reference Counting uses qualified pointers56// that require special addressof() signatures. When57// _LIBCUDACXX_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler58// itself is providing these definitions. Otherwise, we provide them.59template <class _Tp>60inline _LIBCUDACXX_INLINE_VISIBILITY61__strong _Tp*62addressof(__strong _Tp& __x) noexcept63{64 return &__x;65}66 67#ifdef _LIBCUDACXX_HAS_OBJC_ARC_WEAK68template <class _Tp>69inline _LIBCUDACXX_INLINE_VISIBILITY70__weak _Tp*71addressof(__weak _Tp& __x) noexcept72{73 return &__x;74}75#endif76 77template <class _Tp>78inline _LIBCUDACXX_INLINE_VISIBILITY79__autoreleasing _Tp*80addressof(__autoreleasing _Tp& __x) noexcept81{82 return &__x;83}84 85template <class _Tp>86inline _LIBCUDACXX_INLINE_VISIBILITY87__unsafe_unretained _Tp*88addressof(__unsafe_unretained _Tp& __x) noexcept89{90 return &__x;91}92#endif93 94template <class _Tp> _Tp* addressof(const _Tp&&) noexcept = delete;95 96_LIBCUDACXX_END_NAMESPACE_STD97 98#endif // _LIBCUDACXX___MEMORY_ADDRESSOF_H99 