rusticl: add debug assertions to avoid truncating casts

v2: reorder commits for cherry-picking

Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33989>
This commit is contained in:
Seán de Búrca 2025-03-12 11:32:43 -07:00 committed by Marge Bot
parent 474d8b6316
commit 4fc4f3425a
3 changed files with 17 additions and 0 deletions

View file

@ -346,6 +346,11 @@ fn get_device_ids(
return Err(CL_DEVICE_NOT_FOUND);
}
debug_assert!(
devs.len() <= cl_uint::MAX as usize,
"number of available devices exceeds `cl_uint::MAX`"
);
// num_devices returns the number of OpenCL devices available that match device_type. If
// num_devices is NULL, this argument is ignored.
// SAFETY: Caller is responsible for providing a null pointer or one valid

View file

@ -916,6 +916,11 @@ fn get_supported_image_formats(
res.sort();
res.dedup();
debug_assert!(
res.len() <= cl_uint::MAX as usize,
"number of supported formats exceeds `cl_uint::MAX`"
);
// `num_image_formats` should be the full count of supported formats,
// regardless of the value of `num_entries`. It may be null, in which case
// it is ignored.

View file

@ -189,6 +189,13 @@ cl_callback!(
impl SVMFreeCb {
pub fn call(self, queue: &Queue, svm_pointers: &mut [usize]) {
// `clEnqueueSVMFree()` takes the length of the `svm_pointers` list as a
// `cl_uint`, so this will only occur in cases of implementation error.
debug_assert!(
svm_pointers.len() <= cl_uint::MAX as usize,
"svm_pointers count must not exceed `cl_uint::MAX`"
);
let (num_svm_pointers, svm_pointers) = if !svm_pointers.is_empty() {
(
svm_pointers.len() as cl_uint,