summaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/patches/53-exception_pointer_msvc.patch
diff options
context:
space:
mode:
authormikhnenko <[email protected]>2024-12-18 19:08:08 +0300
committermikhnenko <[email protected]>2024-12-18 19:29:26 +0300
commit7ed76959e6c06dbc4c249ce0f3b930463a6b65db (patch)
tree0e9528cb7261812a5ae7ed177048721eaebf8ed0 /contrib/libs/cxxsupp/libcxx/patches/53-exception_pointer_msvc.patch
parent4c8e7f015711b5175d63e1a87cbd40c49ce7aa70 (diff)
libc++: Run clang-format from upstream and update to 9783f28cbb155e4a8d49c12e1c60ce14dcfaf0c7
commit_hash:ca4954fe054e5a7190ad11ab71bfc7ca0965bca2
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/patches/53-exception_pointer_msvc.patch')
-rw-r--r--contrib/libs/cxxsupp/libcxx/patches/53-exception_pointer_msvc.patch142
1 files changed, 60 insertions, 82 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/patches/53-exception_pointer_msvc.patch b/contrib/libs/cxxsupp/libcxx/patches/53-exception_pointer_msvc.patch
index aab087d09f4..eb84ac68b10 100644
--- a/contrib/libs/cxxsupp/libcxx/patches/53-exception_pointer_msvc.patch
+++ b/contrib/libs/cxxsupp/libcxx/patches/53-exception_pointer_msvc.patch
@@ -1,8 +1,8 @@
diff --git a/src/support/runtime/exception_pointer_msvc.ipp b/src/support/runtime/exception_pointer_msvc.ipp
-index 9e7f392..c88c68c 100644
+index b87742b..43ac8ca 100644
--- a/src/support/runtime/exception_pointer_msvc.ipp
+++ b/src/support/runtime/exception_pointer_msvc.ipp
-@@ -7,70 +7,242 @@
+@@ -7,61 +7,226 @@
//
//===----------------------------------------------------------------------===//
@@ -18,15 +18,13 @@ index 9e7f392..c88c68c 100644
-_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrSwap(void*, void*);
-_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCurrentException(void*);
-[[noreturn]] _LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrRethrow(const void*);
--_LIBCPP_CRT_FUNC void __cdecl
--__ExceptionPtrCopyException(void*, const void*, const void*);
+-_LIBCPP_CRT_FUNC void __cdecl __ExceptionPtrCopyException(void*, const void*, const void*);
+#include <atomic>
+#include <cstdint>
+#include <cstring>
+#include <malloc.h>
+#include <windows.h> // For RtlPcToFileHeader function
-
--namespace std {
++
+struct EHCatchableType {
+ uint32_t properties;
+ int32_t type_info;
@@ -36,34 +34,20 @@ index 9e7f392..c88c68c 100644
+ uint32_t size;
+ int32_t copy_function;
+};
-
--exception_ptr::exception_ptr() noexcept { __ExceptionPtrCreate(this); }
--exception_ptr::exception_ptr(nullptr_t) noexcept { __ExceptionPtrCreate(this); }
++
+struct EHCatchableTypeArray {
+ uint32_t catchable_types;
+ // It is variable size but we only need the first element of this array
+ int32_t array_of_catchable_types[1];
+};
-
--exception_ptr::exception_ptr(const exception_ptr& __other) noexcept {
-- __ExceptionPtrCopy(this, &__other);
--}
--exception_ptr& exception_ptr::operator=(const exception_ptr& __other) noexcept {
-- __ExceptionPtrAssign(this, &__other);
-- return *this;
--}
++
+struct EHThrowInfo {
+ uint32_t attributes;
+ int32_t unwind;
+ int32_t forward_compat;
+ int32_t catchable_type_array;
+};
-
--exception_ptr& exception_ptr::operator=(nullptr_t) noexcept {
-- exception_ptr dummy;
-- __ExceptionPtrAssign(this, &dummy);
-- return *this;
--}
++
+struct EHParameters {
+ uint32_t magic_number;
+ void* exception_object;
@@ -72,8 +56,7 @@ index 9e7f392..c88c68c 100644
+ uintptr_t throw_image_base;
+#endif
+};
-
--exception_ptr::~exception_ptr() noexcept { __ExceptionPtrDestroy(this); }
++
+struct EHExceptionRecord {
+ uint32_t exception_code;
+ uint32_t exception_flags;
@@ -82,10 +65,7 @@ index 9e7f392..c88c68c 100644
+ uint32_t number_of_parameters;
+ EHParameters parameters;
+};
-
--exception_ptr::operator bool() const noexcept {
-- return __ExceptionPtrToBool(this);
--}
++
+// defined in vcruntime<ver>.dll
+extern "C" EHExceptionRecord** __current_exception();
+
@@ -95,8 +75,7 @@ index 9e7f392..c88c68c 100644
+#ifdef __clang__
+struct _ThrowInfo;
+// defined in vcruntime<ver>.dll
-+extern "C" _LIBCPP_NORETURN void __stdcall _CxxThrowException(
-+ void* __exc, _ThrowInfo* __throw_info);
++extern "C" _LIBCPP_NORETURN void __stdcall _CxxThrowException(void* __exc, _ThrowInfo* __throw_info);
+#endif
+
+namespace {
@@ -110,15 +89,12 @@ index 9e7f392..c88c68c 100644
+ template <class T>
+ T convert(int32_t offset) {
+#ifdef _M_AMD64
-+ uintptr_t value = reinterpret_cast<uintptr_t>(image_base) +
-+ static_cast<uintptr_t>(offset);
++ uintptr_t value = reinterpret_cast<uintptr_t>(image_base) + static_cast<uintptr_t>(offset);
+#else
+ uintptr_t value = static_cast<uintptr_t>(offset);
+#endif
+ T res;
-+ static_assert(
-+ sizeof(value) == sizeof(res),
-+ "Can only convert to pointers or pointers to member functions");
++ static_assert(sizeof(value) == sizeof(res), "Can only convert to pointers or pointers to member functions");
+ memcpy(&res, &value, sizeof(value));
+ return res;
+ }
@@ -129,31 +105,26 @@ index 9e7f392..c88c68c 100644
+ if (exc_type->copy_function == 0) {
+ memcpy(dst, src, exc_type->size);
+ } else if (exc_type->properties & virtual_base) {
-+ auto copy_constructor =
-+ convert<void (Temp::*)(const void*, int)>(exc_type->copy_function);
++ auto copy_constructor = convert<void (Temp::*)(const void*, int)>(exc_type->copy_function);
+ ((Temp*)dst->*copy_constructor)(src, 1);
+ } else {
-+ auto copy_constructor =
-+ convert<void (Temp::*)(const void*)>(exc_type->copy_function);
++ auto copy_constructor = convert<void (Temp::*)(const void*)>(exc_type->copy_function);
+ ((Temp*)dst->*copy_constructor)(src);
+ }
+ }
+
+ EHCatchableType* exception_type() {
+ return convert<EHCatchableType*>(
-+ convert<EHCatchableTypeArray*>(throw_info->catchable_type_array)
-+ ->array_of_catchable_types[0]);
++ convert<EHCatchableTypeArray*>(throw_info->catchable_type_array)->array_of_catchable_types[0]);
+ }
+
+ ExceptionPtr(const void* exception_object_, const EHThrowInfo* throw_info_)
+ : exception_object(nullptr), throw_info(throw_info_), counter(1) {
+#ifdef _M_AMD64
-+ RtlPcToFileHeader(
-+ reinterpret_cast<PVOID>(const_cast<EHThrowInfo*>(throw_info)),
-+ &image_base);
++ RtlPcToFileHeader(reinterpret_cast<PVOID>(const_cast<EHThrowInfo*>(throw_info)), &image_base);
+#endif
+ EHCatchableType* exc_type = exception_type();
-+ this->exception_object = malloc(exc_type->size);
++ this->exception_object = malloc(exc_type->size);
+ if (this->exception_object == nullptr) {
+ throw std::bad_alloc();
+ }
@@ -168,25 +139,23 @@ index 9e7f392..c88c68c 100644
+ }
+ free(exception_object);
+ }
-
--bool operator==(const exception_ptr& __x, const exception_ptr& __y) noexcept {
-- return __ExceptionPtrCompare(&__x, &__y);
++
+ // _bad_alloc_storage must be initialized before bad_alloc, so we declare and define it first.
+ static std::bad_alloc _bad_alloc_storage;
+ static ExceptionPtr bad_alloc;
-+ //static ExceptionPtr bad_exception;
++ // static ExceptionPtr bad_exception;
+};
+
+#ifdef __clang__
-+#pragma clang diagnostic push
-+#pragma clang diagnostic ignored "-Waddress-of-temporary"
++# pragma clang diagnostic push
++# pragma clang diagnostic ignored "-Waddress-of-temporary"
+#endif
+
+std::bad_alloc ExceptionPtr::_bad_alloc_storage;
+
-+ExceptionPtr ExceptionPtr::bad_alloc(
-+ &ExceptionPtr::_bad_alloc_storage,
-+ reinterpret_cast<const EHThrowInfo*>(__GetExceptionInfo(ExceptionPtr::_bad_alloc_storage)));
++ExceptionPtr
++ ExceptionPtr::bad_alloc(&ExceptionPtr::_bad_alloc_storage,
++ reinterpret_cast<const EHThrowInfo*>(__GetExceptionInfo(ExceptionPtr::_bad_alloc_storage)));
+
+/* ExceptionPtr
+ExceptionPtr::bad_exception(&std::bad_exception(),
@@ -194,24 +163,32 @@ index 9e7f392..c88c68c 100644
+ __GetExceptionInfo(std::bad_exception()))); */
+
+#ifdef __clang__
-+#pragma clang diagnostic pop
++# pragma clang diagnostic pop
+#endif
+
+} // namespace
-+
-+namespace std {
-+
-+exception_ptr::exception_ptr(const exception_ptr& __other) noexcept
-+ : __ptr_(__other.__ptr_) {
+
+ namespace std {
+
+-exception_ptr::exception_ptr() noexcept { __ExceptionPtrCreate(this); }
+-exception_ptr::exception_ptr(nullptr_t) noexcept { __ExceptionPtrCreate(this); }
+-
+-exception_ptr::exception_ptr(const exception_ptr& __other) noexcept { __ExceptionPtrCopy(this, &__other); }
+-exception_ptr& exception_ptr::operator=(const exception_ptr& __other) noexcept {
+- __ExceptionPtrAssign(this, &__other);
+- return *this;
++exception_ptr::exception_ptr(const exception_ptr& __other) noexcept : __ptr_(__other.__ptr_) {
+ if (__ptr_) {
+ reinterpret_cast<ExceptionPtr*>(__ptr_)->counter.fetch_add(1);
+ }
}
-+exception_ptr& exception_ptr::
-+operator=(const exception_ptr& __other) noexcept {
+-exception_ptr& exception_ptr::operator=(nullptr_t) noexcept {
+- exception_ptr dummy;
+- __ExceptionPtrAssign(this, &dummy);
++exception_ptr& exception_ptr::operator=(const exception_ptr& __other) noexcept {
+ auto before = __ptr_;
-+ __ptr_ = __other.__ptr_;
++ __ptr_ = __other.__ptr_;
+ if (__ptr_) {
+ reinterpret_cast<ExceptionPtr*>(__ptr_)->counter.fetch_add(1);
+ }
@@ -220,11 +197,15 @@ index 9e7f392..c88c68c 100644
+ delete reinterpret_cast<ExceptionPtr*>(before);
+ }
+ }
-+ return *this;
-+}
+ return *this;
+ }
--void swap(exception_ptr& lhs, exception_ptr& rhs) noexcept {
-- __ExceptionPtrSwap(&rhs, &lhs);
+-exception_ptr::~exception_ptr() noexcept { __ExceptionPtrDestroy(this); }
+-
+-exception_ptr::operator bool() const noexcept { return __ExceptionPtrToBool(this); }
+-
+-bool operator==(const exception_ptr& __x, const exception_ptr& __y) noexcept {
+- return __ExceptionPtrCompare(&__x, &__y);
+exception_ptr::~exception_ptr() noexcept {
+ if (__ptr_) {
+ if (reinterpret_cast<ExceptionPtr*>(__ptr_)->counter.fetch_sub(1) == 1) {
@@ -233,23 +214,23 @@ index 9e7f392..c88c68c 100644
+ }
}
+-void swap(exception_ptr& lhs, exception_ptr& rhs) noexcept { __ExceptionPtrSwap(&rhs, &lhs); }
+-
-exception_ptr __copy_exception_ptr(void* __except, const void* __ptr) {
- exception_ptr __ret = nullptr;
- if (__ptr)
- __ExceptionPtrCopyException(&__ret, __except, __ptr);
- return __ret;
-+exception_ptr __copy_exception_ptr(void* exception_object,
-+ const void* throw_info) {
++exception_ptr __copy_exception_ptr(void* exception_object, const void* throw_info) {
+ ExceptionPtr* ptr;
+ try {
-+ ptr = new ExceptionPtr(exception_object,
-+ reinterpret_cast<const EHThrowInfo*>(throw_info));
++ ptr = new ExceptionPtr(exception_object, reinterpret_cast<const EHThrowInfo*>(throw_info));
+ } catch (const std::bad_alloc&) {
+ ptr = &ExceptionPtr::bad_alloc;
+ ptr->counter.fetch_add(1);
+ } catch (...) {
-+ //ptr = &ExceptionPtr::bad_exception;
-+ //ptr->counter.fetch_add(1);
++ // ptr = &ExceptionPtr::bad_exception;
++ // ptr->counter.fetch_add(1);
+ std::terminate();
+ }
+ exception_ptr res;
@@ -263,26 +244,23 @@ index 9e7f392..c88c68c 100644
- return __ret;
+ EHExceptionRecord** record = __current_exception();
+ if (*record && !std::uncaught_exception()) {
-+ return __copy_exception_ptr((*record)->parameters.exception_object,
-+ (*record)->parameters.throw_info);
++ return __copy_exception_ptr((*record)->parameters.exception_object, (*record)->parameters.throw_info);
+ }
+ return exception_ptr();
}
- _LIBCPP_NORETURN
--void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); }
-+void rethrow_exception(exception_ptr p) {
+-_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) { __ExceptionPtrRethrow(&p); }
++_LIBCPP_NORETURN void rethrow_exception(exception_ptr p) {
+ if (!p) {
+ throw std::bad_exception();
+ }
-+ ExceptionPtr* exc_ptr = reinterpret_cast<ExceptionPtr*>(p.__ptr_);
++ ExceptionPtr* exc_ptr = reinterpret_cast<ExceptionPtr*>(p.__ptr_);
+ EHCatchableType* exc_type = exc_ptr->exception_type();
+ // _CxxThrowException doesn't call free on exception object so we must
+ // allocate it on the stack.
+ void* dst = _alloca(exc_type->size);
+ exc_ptr->copy(dst, exc_ptr->exception_object, exc_type);
-+ auto throw_info = reinterpret_cast<_ThrowInfo*>(
-+ const_cast<EHThrowInfo*>(exc_ptr->throw_info));
++ auto throw_info = reinterpret_cast<_ThrowInfo*>(const_cast<EHThrowInfo*>(exc_ptr->throw_info));
+ // For some reason clang doesn't call p destructor during unwinding.
+ // So we must clear it ourselves.
+ p = nullptr;