Skip to content

[UR][HIP] Make ur_context_handle_t_ destructor non-throwing#20887

Merged
kswiecicki merged 4 commits into
syclfrom
issue-20811-nonthrowing-destructor
Jan 13, 2026
Merged

[UR][HIP] Make ur_context_handle_t_ destructor non-throwing#20887
kswiecicki merged 4 commits into
syclfrom
issue-20811-nonthrowing-destructor

Conversation

@kekaczma
Copy link
Copy Markdown
Contributor

@kekaczma kekaczma commented Dec 12, 2025

UR_CHECK_ERROR may throw or abort, which is unsafe to use from a destructor. If an exception escapes during stack unwinding, std::terminate would be called.

Replace UR_CHECK_ERROR in ur_context_handle_t_ destructor with a non-throwing, best-effort cleanup. In debug builds, failures are reported via assert/log, while release builds avoid throwing from the destructor.

fixes: #20811

UR_CHECK_ERROR may throw or abort, which is unsafe to use from a destructor.
If an exception escapes during stack unwinding, std::terminate would be called.

Replace UR_CHECK_ERROR in ur_context_handle_t_ destructor with a non-throwing,
best-effort cleanup. In debug builds, failures are reported via assert/log,
while release builds avoid throwing from the destructor.

This fixes Coverity CID 519631, issue: [Coverity][UR] Potentially throwing function is called from a destructor
Make the CUDA context destructor non-throwing by catching exceptions
and using best-effort cleanup with logging and debug asserts.

Related to Coverity CID 519631.
urAdapterRelease() always returns UR_RESULT_SUCCESS, making the
error-checking code unreachable dead code. Exceptions from the
call are already handled by the catch-all block.
Comment thread unified-runtime/source/adapters/cuda/context.hpp Outdated
@github-actions
Copy link
Copy Markdown
Contributor

@intel/llvm-gatekeepers please consider merging

1 similar comment
@github-actions
Copy link
Copy Markdown
Contributor

@intel/llvm-gatekeepers please consider merging

@bratpiorka bratpiorka marked this pull request as draft December 22, 2025 15:20
The called functions (umfPoolDestroy, umfMemoryProviderDestroy,
urAdapterRelease) cannot throw exceptions:
- UMF functions are C APIs (extern C)
- urAdapterRelease and destructors are noexcept in C++11+
@kekaczma
Copy link
Copy Markdown
Contributor Author

The failing test is not related with this PR, it's a known issue (20595).

@kekaczma kekaczma marked this pull request as ready for review January 13, 2026 12:28
@kswiecicki kswiecicki merged commit 936832c into sycl Jan 13, 2026
55 of 58 checks passed
@bader bader deleted the issue-20811-nonthrowing-destructor branch January 23, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Coverity][UR] Potentially throwing function is called from a destructor

3 participants