[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)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Fri Oct 20 22:34:24 PDT 2023


================
@@ -51,11 +69,34 @@ class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {
 template <class _Ep>
 _LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
 #  ifndef _LIBCPP_HAS_NO_EXCEPTIONS
+#    if defined(LIBCXXRT) || defined(LIBCXX_BUILDING_LIBCXXABI)
+  using _Ep2 = __decay_t<_Ep>;
+  void* __ex = exception_ptr::__init_native_exception(
+      sizeof(_Ep), const_cast<std::type_info*>(&typeid(_Ep)), exception_ptr::__dest_thunk<_Ep2>);
----------------
frederick-vs-ja wrote:

> Can't use `typeid` with -fno-rtti, but exceptions can be used with -fno-rtti so the previous impl would work. So this code should all be in a !_LIBCPP_HAS_NO_RTTI ifdef.

Hmm... (at least on Itanium ABI?) when exceptions need to be thrown, `type_info` objects are generated and passed on throwing even if -fno-rtti is used.

Is there any intrinsic to obtain RTTI for EH when -fno-rtti is used?

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


More information about the libcxx-commits mailing list