compiler: use addr_of!

This commit is contained in:
Pavel Grigorenko 2024-02-24 16:47:34 +03:00
parent ff187a92d8
commit 613cb3262d
No known key found for this signature in database
GPG key ID: 52BFCC6ED389F777
7 changed files with 9 additions and 9 deletions

View file

@ -313,7 +313,7 @@ fn get_llvm_object_symbols(
llvm::LLVMRustGetSymbols(
buf.as_ptr(),
buf.len(),
&mut *state as *mut &mut _ as *mut c_void,
std::ptr::addr_of_mut!(*state) as *mut c_void,
callback,
error_callback,
)

View file

@ -169,7 +169,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
fn print_pass_timings(&self) {
unsafe {
let mut size = 0;
let cstr = llvm::LLVMRustPrintPassTimings(&mut size as *mut usize);
let cstr = llvm::LLVMRustPrintPassTimings(std::ptr::addr_of_mut!(size));
if cstr.is_null() {
println!("failed to get pass timings");
} else {
@ -182,7 +182,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
fn print_statistics(&self) {
unsafe {
let mut size = 0;
let cstr = llvm::LLVMRustPrintStatistics(&mut size as *mut usize);
let cstr = llvm::LLVMRustPrintStatistics(std::ptr::addr_of_mut!(size));
if cstr.is_null() {
println!("failed to get pass stats");
} else {

View file

@ -435,7 +435,7 @@ pub(crate) fn print(req: &PrintRequest, mut out: &mut dyn PrintBackendInfo, sess
&tm,
cpu_cstring.as_ptr(),
callback,
&mut out as *mut &mut dyn PrintBackendInfo as *mut c_void,
std::ptr::addr_of_mut!(out) as *mut c_void,
);
}
}

View file

@ -429,7 +429,7 @@ impl<T> RwLock<T> {
#[inline(always)]
pub fn leak(&self) -> &T {
let guard = self.read();
let ret = unsafe { &*(&*guard as *const T) };
let ret = unsafe { &*std::ptr::addr_of!(*guard) };
std::mem::forget(guard);
ret
}

View file

@ -233,7 +233,7 @@ impl<'sess> OnDiskCache<'sess> {
for (index, file) in files.iter().enumerate() {
let index = SourceFileIndex(index as u32);
let file_ptr: *const SourceFile = &**file as *const _;
let file_ptr: *const SourceFile = std::ptr::addr_of!(**file);
file_to_file_index.insert(file_ptr, index);
let source_file_id = EncodedSourceFileId::new(tcx, file);
file_index_to_stable_id.insert(index, source_file_id);
@ -835,7 +835,7 @@ pub struct CacheEncoder<'a, 'tcx> {
impl<'a, 'tcx> CacheEncoder<'a, 'tcx> {
#[inline]
fn source_file_index(&mut self, source_file: Lrc<SourceFile>) -> SourceFileIndex {
self.file_to_file_index[&(&*source_file as *const SourceFile)]
self.file_to_file_index[&std::ptr::addr_of!(*source_file)]
}
/// Encode something with additional information that allows to do some

View file

@ -61,7 +61,7 @@ impl<T> List<T> {
// length) that is 64-byte aligned, thus featuring the necessary
// trailing padding for elements with up to 64-byte alignment.
static EMPTY_SLICE: InOrder<usize, MaxAlign> = InOrder(0, MaxAlign);
unsafe { &*(&EMPTY_SLICE as *const _ as *const List<T>) }
unsafe { &*(std::ptr::addr_of!(EMPTY_SLICE) as *const List<T>) }
}
pub fn len(&self) -> usize {

View file

@ -208,7 +208,7 @@ where
if TLV.is_set() {
Err(Error::from("StableMIR already running"))
} else {
let ptr: *const () = &context as *const &_ as _;
let ptr: *const () = std::ptr::addr_of!(context) as _;
TLV.set(&Cell::new(ptr), || Ok(f()))
}
}