Module: Mesa
Branch: main
Commit: e3312455419c2cc7f178e1eddf5519c8ed449efb
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=e3312455419c2cc7f178e1eddf5519c8ed449efb

Author: Karol Herbst <[email protected]>
Date:   Thu Aug  3 15:17:41 2023 +0200

rusticl/kernel: mark can_remove_var as unsafe and document it

Signed-off-by: Karol Herbst <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24470>

---

 src/gallium/frontends/rusticl/core/kernel.rs | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/gallium/frontends/rusticl/core/kernel.rs 
b/src/gallium/frontends/rusticl/core/kernel.rs
index 867dc90d1a4..ff077b23d7b 100644
--- a/src/gallium/frontends/rusticl/core/kernel.rs
+++ b/src/gallium/frontends/rusticl/core/kernel.rs
@@ -377,12 +377,18 @@ fn opt_nir(nir: &mut NirShader, dev: &Device) {
     } {}
 }
 
-extern "C" fn can_remove_var(var: *mut nir_variable, _: *mut c_void) -> bool {
+/// # Safety
+///
+/// Only safe to call when `var` is a valid pointer to a valid [`nir_variable`]
+unsafe extern "C" fn can_remove_var(var: *mut nir_variable, _: *mut c_void) -> 
bool {
+    // SAFETY: It is the caller's responsibility to provide a valid and 
aligned pointer
+    let var_type = unsafe { (*var).type_ };
+    // SAFETY: `nir_variable`'s type invariant guarantees that the `type_` 
field is valid and
+    // properly aligned.
     unsafe {
-        let var = var.as_ref().unwrap();
-        !glsl_type_is_image(var.type_)
-            && !glsl_type_is_texture(var.type_)
-            && !glsl_type_is_sampler(var.type_)
+        !glsl_type_is_image(var_type)
+            && !glsl_type_is_texture(var_type)
+            && !glsl_type_is_sampler(var_type)
     }
 }
 

Reply via email to