From aa775cf8355303f6e80b23b11572aa91c2a73ba5 Mon Sep 17 00:00:00 2001 From: David Chisnall Date: Sat, 30 Nov 2019 11:24:49 +0000 Subject: [PATCH] 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. --- Test/CMakeLists.txt | 1 + eh_personality.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Test/CMakeLists.txt b/Test/CMakeLists.txt index 09e5902..7e82711 100644 --- a/Test/CMakeLists.txt +++ b/Test/CMakeLists.txt @@ -139,6 +139,7 @@ addtest_variants("CXXExceptions" "CXXException.m;CXXException.cc" true) addtest_variants("ForwardDeclareProtocolAccess" "ForwardDeclareProtocolAccess.m;ForwardDeclareProtocol.m" true) if (ENABLE_OBJCXX) addtest_variants(ObjCXXEHInterop "ObjCXXEHInterop.mm;ObjCXXEHInterop.m" true) + addtest_variants(ObjCXXEHInterop_arc "ObjCXXEHInterop_arc.mm;ObjCXXEHInterop_arc.m" true) endif() # Some tests use enough memory that they fail on CI intermittently if they diff --git a/eh_personality.c b/eh_personality.c index 82d2c6e..3f0f8df 100644 --- a/eh_personality.c +++ b/eh_personality.c @@ -575,7 +575,8 @@ id objc_begin_catch(struct _Unwind_Exception *exceptionObject) { DEBUG_LOG("c++ catch\n"); td->current_exception_type = CXX; - return __cxa_begin_catch(exceptionObject); + id *obj = __cxa_begin_catch(exceptionObject); + return obj ? *obj : nil; } DEBUG_LOG("foreign exception catch\n"); // Box if we have a boxing function.