[libc++] [libc++abi] Regression: std::make_exception_ptr breaks catching ObjC objects on rethrow #135089
Labels
libc++abi
libc++abi C++ Runtime Library. Not libc++.
libc++
libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
objective-c
This is a regression introduced in LLVM commit 51e91b6 (PR #65534). The following code used to work prior to the change:
This kind of code may be written when working with an Objective-C++ codebase that uses exceptions, and NSError*/NSException* types need to be handled alongside C++ errors. I believe this is supported because Objective-C exceptions are interoperable with C++ exceptions.
This broke with the aforementioned commit because
std::make_exception_ptr
no longer internally throws the exception object and usesstd::current_exception
to capture the value. Instead, it directly allocates and populates the__cxxabiv1::__cxa_exception
using the C++ type information. However, when an ObjC exception is thrown natively, it uses a different representation for the exception's typeinfo.This is apparent when looking at the assembly output from
clang++ -S
. In the sample program above, the Catch TypeInfos inGCC_except_table0
forRecoverException()
is a_OBJC_EHTYPE_$_NSError
. This corresponds to the type stored in astruct objc_exception
produced in the ObjC runtime when an object is thrown viaobjc_exception_throw
.But in the assembly produced after that commit, the template instantiation for
std::exception_ptr std::make_exception_ptr<NSError*>(NSError*)
produces an exception with a reference to the__ZTIP7NSError
typeinfo. I.e., after the commit, the exception stores the C++ typeinfo for the object, rather than the ObjC typeinfo. When the exception is rethrown, the catch arms fail to match because the typeinfos between the catch arm and the exception object do not match.Putting a breakpoint on
RecoverException
and then inspecting the argument shows this too. After the commit:Before the commit:
Also filed as FB17179536.
The text was updated successfully, but these errors were encountered: