diff --git a/src/gallium/frontends/rusticl/core/platform.rs b/src/gallium/frontends/rusticl/core/platform.rs index f80ed9d3ceb..40f18f2ca51 100644 --- a/src/gallium/frontends/rusticl/core/platform.rs +++ b/src/gallium/frontends/rusticl/core/platform.rs @@ -7,6 +7,8 @@ use mesa_rust_gen::*; use rusticl_opencl_gen::*; use std::env; +use std::ptr::addr_of; +use std::ptr::addr_of_mut; use std::sync::Once; #[repr(C)] @@ -73,7 +75,8 @@ static mut PLATFORM_FEATURES: PlatformFeatures = PlatformFeatures { }; fn load_env() { - let debug = unsafe { &mut PLATFORM_DBG }; + // SAFETY: no other references exist at this point + let debug = unsafe { &mut *addr_of_mut!(PLATFORM_DBG) }; if let Ok(debug_flags) = env::var("RUSTICL_DEBUG") { for flag in debug_flags.split(',') { match flag { @@ -88,7 +91,8 @@ fn load_env() { } } - let features = unsafe { &mut PLATFORM_FEATURES }; + // SAFETY: no other references exist at this point + let features = unsafe { &mut *addr_of_mut!(PLATFORM_FEATURES) }; if let Ok(feature_flags) = env::var("RUSTICL_FEATURES") { for flag in feature_flags.split(',') { match flag { @@ -109,17 +113,17 @@ impl Platform { pub fn get() -> &'static Self { debug_assert!(PLATFORM_ONCE.is_completed()); // SAFETY: no mut references exist at this point - unsafe { &PLATFORM } + unsafe { &*addr_of!(PLATFORM) } } pub fn dbg() -> &'static PlatformDebug { debug_assert!(PLATFORM_ENV_ONCE.is_completed()); - unsafe { &PLATFORM_DBG } + unsafe { &*addr_of!(PLATFORM_DBG) } } pub fn features() -> &'static PlatformFeatures { debug_assert!(PLATFORM_ENV_ONCE.is_completed()); - unsafe { &PLATFORM_FEATURES } + unsafe { &*addr_of!(PLATFORM_FEATURES) } } fn init(&mut self) { diff --git a/src/gallium/frontends/rusticl/core/program.rs b/src/gallium/frontends/rusticl/core/program.rs index 8b9f1cf55d2..ffdd1a5056b 100644 --- a/src/gallium/frontends/rusticl/core/program.rs +++ b/src/gallium/frontends/rusticl/core/program.rs @@ -20,6 +20,7 @@ use std::collections::HashSet; use std::ffi::CString; use std::mem::size_of; use std::ptr; +use std::ptr::addr_of; use std::slice; use std::sync::Arc; use std::sync::Mutex; @@ -55,7 +56,7 @@ fn get_disk_cache() -> &'static Option { DISK_CACHE_ONCE.call_once(|| { DISK_CACHE = DiskCache::new("rusticl", &func_ptrs, 0); }); - &DISK_CACHE + &*addr_of!(DISK_CACHE) } }