Skip to content

Commit aa775cf

Browse files
committed
Fix ObjC++ interop bug.
The reworked wrapping of C++ exceptions meant that we were missing a dereference of the result of __cxa_begin_catch. Add a test that triggers this issue. It would have occurred in the non-ARC version if we actually did anything with the exception, but compiling it in ARC mode makes the compiler insert retain / autorelease around the exception object to ensure that it remains live.
1 parent 8e59872 commit aa775cf

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

Test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ addtest_variants("CXXExceptions" "CXXException.m;CXXException.cc" true)
139139
addtest_variants("ForwardDeclareProtocolAccess" "ForwardDeclareProtocolAccess.m;ForwardDeclareProtocol.m" true)
140140
if (ENABLE_OBJCXX)
141141
addtest_variants(ObjCXXEHInterop "ObjCXXEHInterop.mm;ObjCXXEHInterop.m" true)
142+
addtest_variants(ObjCXXEHInterop_arc "ObjCXXEHInterop_arc.mm;ObjCXXEHInterop_arc.m" true)
142143
endif()
143144

144145
# Some tests use enough memory that they fail on CI intermittently if they

eh_personality.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,8 @@ id objc_begin_catch(struct _Unwind_Exception *exceptionObject)
575575
{
576576
DEBUG_LOG("c++ catch\n");
577577
td->current_exception_type = CXX;
578-
return __cxa_begin_catch(exceptionObject);
578+
id *obj = __cxa_begin_catch(exceptionObject);
579+
return obj ? *obj : nil;
579580
}
580581
DEBUG_LOG("foreign exception catch\n");
581582
// Box if we have a boxing function.

0 commit comments

Comments
 (0)