From 95fe153c7a1e6077056bb8cecf3b61244330f60b Mon Sep 17 00:00:00 2001 From: Sergey Semenov Date: Thu, 6 Nov 2025 07:43:02 -0800 Subject: [PATCH] [SYCL] Fix uncaught exception in DeviceGlobalUSMMem dtor --- .../source/detail/device_global_map_entry.cpp | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/sycl/source/detail/device_global_map_entry.cpp b/sycl/source/detail/device_global_map_entry.cpp index 25704caaee6de..b5dec899f2759 100644 --- a/sycl/source/detail/device_global_map_entry.cpp +++ b/sycl/source/detail/device_global_map_entry.cpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace sycl { inline namespace _V1 { @@ -21,16 +22,21 @@ DeviceGlobalUSMMem::~DeviceGlobalUSMMem() { // removeAssociatedResources is expected to have cleaned up both the pointer // and the event. When asserts are enabled the values are set, so we check // these here. - auto ContextImplPtr = MAllocatingContext.lock(); - if (ContextImplPtr) { - if (MPtr != nullptr) { - detail::usm::freeInternal(MPtr, ContextImplPtr.get()); - MPtr = nullptr; - } - if (MInitEvent != nullptr) { - ContextImplPtr->getAdapter().call(MInitEvent); - MInitEvent = nullptr; + try { + auto ContextImplPtr = MAllocatingContext.lock(); + if (ContextImplPtr) { + if (MPtr != nullptr) { + detail::usm::freeInternal(MPtr, ContextImplPtr.get()); + MPtr = nullptr; + } + if (MInitEvent != nullptr) { + ContextImplPtr->getAdapter().call( + MInitEvent); + MInitEvent = nullptr; + } } + } catch (std::exception &e) { + __SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~DeviceGlobalUSMMem", e); } assert(MPtr == nullptr && "MPtr has not been cleaned up.");