[RISCV] Fix mgather -> riscv.masked.strided.load combine not extending indices (...
[llvm-project.git] / libcxx / include / __exception / exception_ptr.h
blob53e2f718bc1b358f53603fe03c94082d91b0cd2c
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___EXCEPTION_EXCEPTION_PTR_H
10 #define _LIBCPP___EXCEPTION_EXCEPTION_PTR_H
12 #include <__availability>
13 #include <__config>
14 #include <__exception/operations.h>
15 #include <__memory/addressof.h>
16 #include <__memory/construct_at.h>
17 #include <__type_traits/decay.h>
18 #include <cstddef>
19 #include <cstdlib>
20 #include <new>
21 #include <typeinfo>
23 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
24 # pragma GCC system_header
25 #endif
27 #ifndef _LIBCPP_ABI_MICROSOFT
29 namespace __cxxabiv1 {
31 extern "C" {
32 _LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw();
33 _LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw();
35 struct __cxa_exception;
36 _LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
37 void*,
38 std::type_info*,
39 void(
40 # if defined(_WIN32)
41 __thiscall
42 # endif
43 *)(void*)) throw();
46 } // namespace __cxxabiv1
48 #endif
50 namespace std { // purposefully not using versioning namespace
52 #ifndef _LIBCPP_ABI_MICROSOFT
54 class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {
55 void* __ptr_;
57 static exception_ptr __from_native_exception_pointer(void*) _NOEXCEPT;
59 template <class _Ep>
60 friend _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep) _NOEXCEPT;
62 public:
63 _LIBCPP_HIDE_FROM_ABI exception_ptr() _NOEXCEPT : __ptr_() {}
64 _LIBCPP_HIDE_FROM_ABI exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {}
66 exception_ptr(const exception_ptr&) _NOEXCEPT;
67 exception_ptr& operator=(const exception_ptr&) _NOEXCEPT;
68 ~exception_ptr() _NOEXCEPT;
70 _LIBCPP_HIDE_FROM_ABI explicit operator bool() const _NOEXCEPT { return __ptr_ != nullptr; }
72 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {
73 return __x.__ptr_ == __y.__ptr_;
76 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {
77 return !(__x == __y);
80 friend _LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT;
81 friend _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr);
84 template <class _Ep>
85 _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
86 # ifndef _LIBCPP_HAS_NO_EXCEPTIONS
87 # if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION && __cplusplus >= 201103L
88 using _Ep2 = __decay_t<_Ep>;
90 void* __ex = __cxxabiv1::__cxa_allocate_exception(sizeof(_Ep));
91 (void)__cxxabiv1::__cxa_init_primary_exception(__ex, const_cast<std::type_info*>(&typeid(_Ep)), [](void* __p) {
92 std::__destroy_at(static_cast<_Ep2*>(__p));
93 });
95 try {
96 ::new (__ex) _Ep2(__e);
97 return exception_ptr::__from_native_exception_pointer(__ex);
98 } catch (...) {
99 __cxxabiv1::__cxa_free_exception(__ex);
100 return current_exception();
102 # else
103 try {
104 throw __e;
105 } catch (...) {
106 return current_exception();
108 # endif
109 # else
110 ((void)__e);
111 std::abort();
112 # endif
115 #else // _LIBCPP_ABI_MICROSOFT
117 class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {
118 _LIBCPP_DIAGNOSTIC_PUSH
119 _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field")
120 void* __ptr1_;
121 void* __ptr2_;
122 _LIBCPP_DIAGNOSTIC_POP
124 public:
125 exception_ptr() _NOEXCEPT;
126 exception_ptr(nullptr_t) _NOEXCEPT;
127 exception_ptr(const exception_ptr& __other) _NOEXCEPT;
128 exception_ptr& operator=(const exception_ptr& __other) _NOEXCEPT;
129 exception_ptr& operator=(nullptr_t) _NOEXCEPT;
130 ~exception_ptr() _NOEXCEPT;
131 explicit operator bool() const _NOEXCEPT;
134 _LIBCPP_EXPORTED_FROM_ABI bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT;
136 inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT {
137 return !(__x == __y);
140 _LIBCPP_EXPORTED_FROM_ABI void swap(exception_ptr&, exception_ptr&) _NOEXCEPT;
142 _LIBCPP_EXPORTED_FROM_ABI exception_ptr __copy_exception_ptr(void* __except, const void* __ptr);
143 _LIBCPP_EXPORTED_FROM_ABI exception_ptr current_exception() _NOEXCEPT;
144 _LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void rethrow_exception(exception_ptr);
146 // This is a built-in template function which automagically extracts the required
147 // information.
148 template <class _E>
149 void* __GetExceptionInfo(_E);
151 template <class _Ep>
152 _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
153 return __copy_exception_ptr(std::addressof(__e), __GetExceptionInfo(__e));
156 #endif // _LIBCPP_ABI_MICROSOFT
157 } // namespace std
159 #endif // _LIBCPP___EXCEPTION_EXCEPTION_PTR_H