From 2e3a6af7faf1841d620baee12993f59cccdd4e4c Mon Sep 17 00:00:00 2001 From: Irina Popa Date: Tue, 17 Jul 2018 16:31:09 +0300 Subject: [PATCH] rustc_codegen_llvm: use safe references for ThinLTOBuffer. --- src/librustc_codegen_llvm/back/lto.rs | 4 ++-- src/librustc_codegen_llvm/llvm/ffi.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs index 27a8b5c1d077..ce56be734d77 100644 --- a/src/librustc_codegen_llvm/back/lto.rs +++ b/src/librustc_codegen_llvm/back/lto.rs @@ -579,7 +579,7 @@ impl Drop for ThinData { } } -pub struct ThinBuffer(*mut llvm::ThinLTOBuffer); +pub struct ThinBuffer(&'static mut llvm::ThinLTOBuffer); unsafe impl Send for ThinBuffer {} unsafe impl Sync for ThinBuffer {} @@ -604,7 +604,7 @@ impl ThinBuffer { impl Drop for ThinBuffer { fn drop(&mut self) { unsafe { - llvm::LLVMRustThinLTOBufferFree(self.0); + llvm::LLVMRustThinLTOBufferFree(&mut *(self.0 as *mut _)); } } } diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs index 6f849e65b2eb..ce10a98938ec 100644 --- a/src/librustc_codegen_llvm/llvm/ffi.rs +++ b/src/librustc_codegen_llvm/llvm/ffi.rs @@ -1571,10 +1571,10 @@ extern "C" { pub fn LLVMRustThinLTOAvailable() -> bool; pub fn LLVMRustPGOAvailable() -> bool; - pub fn LLVMRustThinLTOBufferCreate(M: &Module) -> *mut ThinLTOBuffer; - pub fn LLVMRustThinLTOBufferFree(M: *mut ThinLTOBuffer); - pub fn LLVMRustThinLTOBufferPtr(M: *const ThinLTOBuffer) -> *const c_char; - pub fn LLVMRustThinLTOBufferLen(M: *const ThinLTOBuffer) -> size_t; + pub fn LLVMRustThinLTOBufferCreate(M: &Module) -> &'static mut ThinLTOBuffer; + pub fn LLVMRustThinLTOBufferFree(M: &'static mut ThinLTOBuffer); + pub fn LLVMRustThinLTOBufferPtr(M: &ThinLTOBuffer) -> *const c_char; + pub fn LLVMRustThinLTOBufferLen(M: &ThinLTOBuffer) -> size_t; pub fn LLVMRustCreateThinLTOData( Modules: *const ThinLTOModule, NumModules: c_uint,