Skip to content

detail::image_mem_impl destructor may throw an exception even though it is implicitly nothrow #16331

Closed
@AlexeySachkov

Description

@AlexeySachkov

The following destructor may throw sycl::exception, but being implicitly nothrow this will result in std::terminate which could be unexpected for our users:

detail::image_mem_impl::~image_mem_impl() {
free_image_mem(this->get_handle(), this->get_descriptor().type,
this->get_device(), this->get_context());
}

Exception could be thrown here:

__SYCL_EXPORT void free_image_mem(image_mem_handle memHandle,
image_type imageType,
const sycl::device &syclDevice,
const sycl::context &syclContext) {
std::shared_ptr<sycl::detail::context_impl> CtxImpl =
sycl::detail::getSyclObjImpl(syclContext);
ur_context_handle_t C = CtxImpl->getHandleRef();
std::shared_ptr<sycl::detail::device_impl> DevImpl =
sycl::detail::getSyclObjImpl(syclDevice);
ur_device_handle_t Device = DevImpl->getHandleRef();
const sycl::detail::AdapterPtr &Adapter = CtxImpl->getAdapter();
if (memHandle.raw_handle != 0) {
if (imageType == image_type::mipmap) {
Adapter->call<sycl::errc::memory_allocation,
sycl::detail::UrApiKind::urBindlessImagesMipmapFreeExp>(
C, Device, memHandle.raw_handle);
} else if (imageType == image_type::standard ||
imageType == image_type::array ||
imageType == image_type::cubemap) {
Adapter->call<sycl::errc::memory_allocation,
sycl::detail::UrApiKind::urBindlessImagesImageFreeExp>(
C, Device, memHandle.raw_handle);
} else {
throw sycl::exception(sycl::make_error_code(sycl::errc::invalid),
"Invalid image type to free");
}
}
}

Either from Plugin->call, or just by falling to that else branch at the end which does direct throw

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions