[libcxx-commits] [libcxxabi] [libc++] [libc++abi] Initialize exception directly in make_exception_ptr if __cxa_init_primary_exception is available in ABI-library (PR #65534)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Oct 25 15:57:37 PDT 2023
================
@@ -53,6 +67,36 @@ exception_ptr& exception_ptr::operator=(const exception_ptr& other) noexcept
return *this;
}
+# if defined(_LIBCPP_EXCEPTION_PTR_DIRECT_INIT)
+void *exception_ptr::__init_native_exception(size_t size, type_info* tinfo, void (*dest)(void*)) noexcept
+{
+ void *(*cxa_init_primary_exception_fn)(void*, std::type_info*, void(*)(void*)) = __cxa_init_primary_exception;
+ if (cxa_init_primary_exception_fn != nullptr)
+ {
+ void* __ex = __cxa_allocate_exception(size);
+ (void)cxa_init_primary_exception_fn(__ex, tinfo, dest);
+ return __ex;
+ }
+ else
+ {
+ return nullptr;
+ }
+}
+
+void exception_ptr::__free_native_exception(void* thrown_object) noexcept
+{
+ __cxa_free_exception(thrown_object);
+}
+
+exception_ptr exception_ptr::__from_native_exception_pointer(void* __e) noexcept
+{
+ exception_ptr ptr{};
+ new (reinterpret_cast<void*>(&ptr)) __exception_ptr::exception_ptr(__e);
----------------
EricWF wrote:
This has got to be an aliasing violation that the compiler can optimize on?
The types have two different sizes.
https://github.com/llvm/llvm-project/pull/65534
More information about the libcxx-commits
mailing list