[libcxx-commits] [libcxx] [libcxxabi] [libc++] [libc++abi] Initialize exception directly in make_exception_ptr if __cxa_init_primary_exception is available in ABI-library (PR #65534)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Nov 16 13:43:18 PST 2023


================
@@ -34,6 +56,37 @@ 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 (_LIBCXX_DTOR_FUNC* dest)(void*)) noexcept
+{
+    __cxa_exception *(*cxa_init_primary_exception_fn)(void*, std::type_info*, void(_LIBCXX_DTOR_FUNC*)(void*)) = __cxa_init_primary_exception;
----------------
ldionne wrote:

We have a usual way of dealing with newly-introduced symbols. I already explained it in my other comment about the `__availability` header. Please use that instead. There is no need for us to check whether the weak symbol exists here and do something different at runtime in case it's not. The only conditional bit we should have is in `exception_ptr.h` where we would do

```
#if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION
// use it
#else
// do the throw dance
#endif
```

https://github.com/llvm/llvm-project/pull/65534


More information about the libcxx-commits mailing list