-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[libc++] Fix std::make_exception_ptr interaction with ObjC #135386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-libcxx Author: None (itrofimow) ChangesClang treats throwing/catching ObjC types differently from C++ types, and omitting the Full diff: https://github.com/llvm/llvm-project/pull/135386.diff 1 Files Affected:
diff --git a/libcxx/include/__exception/exception_ptr.h b/libcxx/include/__exception/exception_ptr.h
index dac5b00b57fe3..167aa4d9b367a 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -92,7 +92,8 @@ class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {
template <class _Ep>
_LIBCPP_HIDE_FROM_ABI exception_ptr make_exception_ptr(_Ep __e) _NOEXCEPT {
# if _LIBCPP_HAS_EXCEPTIONS
-# if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION && __cplusplus >= 201103L
+ // Clang treats throwing ObjC types differently, and we have to preserve original throw-ing behavior
+# if !defined(__OBJC__) && _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION && __cplusplus >= 201103L
using _Ep2 = __decay_t<_Ep>;
void* __ex = __cxxabiv1::__cxa_allocate_exception(sizeof(_Ep));
|
It's not great to condition only on If you switch to the As a refinement to my suggestion on the issue, I think |
Are you still planning to update this patch? |
Hi! Yes, sorry, just got back to office I was thinking, wouldn't just |
You mean without the OBJC ifdef? I think that would be OK. But IMO it's not actually an improvement, because the condition is no longer clearly connected with the actual reason for the existence of the alternate codepath. |
I don't think CI failure has to do with these changes, @jyknight could you please have a look? |
using _Ep2 = __decay_t<_Ep>; | ||
|
||
void* __ex = __cxxabiv1::__cxa_allocate_exception(sizeof(_Ep)); | ||
# if _LIBCPP_AVAILABILITY_HAS_INIT_PRIMARY_EXCEPTION && __cplusplus >= 201703L |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should really be _LIBCPP_STD_VER >= 17
. Also, why did this change from C++11 to C++17?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is about language-level features rather than libc++ features: c++11 or higher was required for the lambda to compile; c++17 or higher is now required for if constexpr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are available as extensions in older versions. No need to put this behind a guard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change looks fine.
But is there any way to add a test-case for this? (It's not clear to me there is since it depends on the non-llvm-project objc runtime, but it'd be great if there was.)
There's some prior art in |
I'll see what I can do about the test for this. |
@itrofimow @jyknight Thanks for the PR. I updated the PR with a test and I refactored the code as a drive-by so it would be easier to understand -- after adding yet another |
We might be able to make it into LLVM 20.1.9 if we end up having such a release. |
Gentle ping @itrofimow @jyknight WDYT about the current PR? It's passing CI and I'd like to get it merged whenever possible! |
Hi @ldionne! Thank you for taking care of this PR, I've got completely consumed by work and absolutely failed to clean up my own mess in time. Personally, I don't think narrowing the "could it be ObjC type" condition any further via compiler intrinsics is worth it: for me (as someone who just reads libcxx source code from time to time, not a maintainer) the mere presence of ObjC-related code/comments in libcxx seems confusing enough, and I'd say that Nice refactoring by you, and I'm happy to see CI finally working. LGTM |
Thanks for the reviews. I'll merge this once CI is green. |
CI is red for reasons unrelated to this patch, landing. |
/cherry-pick fcc09b6 |
/pull-request #147554 |
Clang treats throwing/catching ObjC types differently from C++ types, and omitting the
throw
instd::make_exception_ptr
breaks ObjC invariants about how types are thrown/caught.Fixes #135089