Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:17

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H
0010 #define _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H
0011 
0012 #include <__config>
0013 #include <__coroutine/coroutine_handle.h>
0014 
0015 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0016 #  pragma GCC system_header
0017 #endif
0018 
0019 #if _LIBCPP_STD_VER >= 20
0020 
0021 _LIBCPP_BEGIN_NAMESPACE_STD
0022 
0023 #  if __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC)
0024 
0025 // [coroutine.noop]
0026 // [coroutine.promise.noop]
0027 struct noop_coroutine_promise {};
0028 
0029 // [coroutine.handle.noop]
0030 template <>
0031 struct _LIBCPP_TEMPLATE_VIS coroutine_handle<noop_coroutine_promise> {
0032 public:
0033   // [coroutine.handle.noop.conv], conversion
0034   _LIBCPP_HIDE_FROM_ABI constexpr operator coroutine_handle<>() const noexcept {
0035     return coroutine_handle<>::from_address(address());
0036   }
0037 
0038   // [coroutine.handle.noop.observers], observers
0039   _LIBCPP_HIDE_FROM_ABI constexpr explicit operator bool() const noexcept { return true; }
0040   _LIBCPP_HIDE_FROM_ABI constexpr bool done() const noexcept { return false; }
0041 
0042   // [coroutine.handle.noop.resumption], resumption
0043   _LIBCPP_HIDE_FROM_ABI constexpr void operator()() const noexcept {}
0044   _LIBCPP_HIDE_FROM_ABI constexpr void resume() const noexcept {}
0045   _LIBCPP_HIDE_FROM_ABI constexpr void destroy() const noexcept {}
0046 
0047   // [coroutine.handle.noop.promise], promise access
0048   _LIBCPP_HIDE_FROM_ABI noop_coroutine_promise& promise() const noexcept {
0049     return *static_cast<noop_coroutine_promise*>(
0050         __builtin_coro_promise(this->__handle_, alignof(noop_coroutine_promise), false));
0051   }
0052 
0053   // [coroutine.handle.noop.address], address
0054   _LIBCPP_HIDE_FROM_ABI constexpr void* address() const noexcept { return __handle_; }
0055 
0056 private:
0057   _LIBCPP_HIDE_FROM_ABI friend coroutine_handle<noop_coroutine_promise> noop_coroutine() noexcept;
0058 
0059 #    if __has_builtin(__builtin_coro_noop)
0060   _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept { this->__handle_ = __builtin_coro_noop(); }
0061 
0062   void* __handle_ = nullptr;
0063 
0064 #    elif defined(_LIBCPP_COMPILER_GCC)
0065   // GCC doesn't implement __builtin_coro_noop().
0066   // Construct the coroutine frame manually instead.
0067   struct __noop_coroutine_frame_ty_ {
0068     static void __dummy_resume_destroy_func() {}
0069 
0070     void (*__resume_)()  = __dummy_resume_destroy_func;
0071     void (*__destroy_)() = __dummy_resume_destroy_func;
0072     struct noop_coroutine_promise __promise_;
0073   };
0074 
0075   static __noop_coroutine_frame_ty_ __noop_coroutine_frame_;
0076 
0077   void* __handle_ = &__noop_coroutine_frame_;
0078 
0079   _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept = default;
0080 
0081 #    endif // __has_builtin(__builtin_coro_noop)
0082 };
0083 
0084 using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>;
0085 
0086 #    if defined(_LIBCPP_COMPILER_GCC)
0087 inline noop_coroutine_handle::__noop_coroutine_frame_ty_ noop_coroutine_handle::__noop_coroutine_frame_{};
0088 #    endif
0089 
0090 // [coroutine.noop.coroutine]
0091 inline _LIBCPP_HIDE_FROM_ABI noop_coroutine_handle noop_coroutine() noexcept { return noop_coroutine_handle(); }
0092 
0093 #  endif // __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC)
0094 
0095 _LIBCPP_END_NAMESPACE_STD
0096 
0097 #endif // __LIBCPP_STD_VER >= 20
0098 
0099 #endif // _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H