about summary refs log tree commit diff
path: root/src/librustc_codegen_llvm
diff options
context:
space:
mode:
authorIrina Popa <irinagpopa@gmail.com>2018-07-17 16:43:49 +0300
committerIrina Popa <irinagpopa@gmail.com>2018-07-30 20:34:51 +0300
commitba006440eeae07cb6d6285a6b64f4374754d2300 (patch)
tree11fb3cb5baea3a15393f3a830efe342e311818ca /src/librustc_codegen_llvm
parent2e3a6af7faf1841d620baee12993f59cccdd4e4c (diff)
downloadrust-ba006440eeae07cb6d6285a6b64f4374754d2300.tar.gz
rust-ba006440eeae07cb6d6285a6b64f4374754d2300.zip
rustc_codegen_llvm: use safe references for ThinLTOData.
Diffstat (limited to 'src/librustc_codegen_llvm')
-rw-r--r--src/librustc_codegen_llvm/back/lto.rs13
-rw-r--r--src/librustc_codegen_llvm/llvm/ffi.rs12
2 files changed, 12 insertions, 13 deletions
diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs
index ce56be734d7..daa2fb05280 100644
--- a/src/librustc_codegen_llvm/back/lto.rs
+++ b/src/librustc_codegen_llvm/back/lto.rs
@@ -423,11 +423,10 @@ fn thin_lto(diag_handler: &Handler,
             thin_modules.len() as u32,
             symbol_white_list.as_ptr(),
             symbol_white_list.len() as u32,
-        );
-        if data.is_null() {
-            let msg = "failed to prepare thin LTO context".to_string();
-            return Err(write::llvm_err(&diag_handler, msg))
-        }
+        ).ok_or_else(|| {
+            write::llvm_err(&diag_handler, "failed to prepare thin LTO context".to_string())
+        })?;
+
         let data = ThinData(data);
         info!("thin LTO data created");
         timeline.record("data");
@@ -566,7 +565,7 @@ struct ThinShared {
     module_names: Vec<CString>,
 }
 
-struct ThinData(*mut llvm::ThinLTOData);
+struct ThinData(&'static mut llvm::ThinLTOData);
 
 unsafe impl Send for ThinData {}
 unsafe impl Sync for ThinData {}
@@ -574,7 +573,7 @@ unsafe impl Sync for ThinData {}
 impl Drop for ThinData {
     fn drop(&mut self) {
         unsafe {
-            llvm::LLVMRustFreeThinLTOData(self.0);
+            llvm::LLVMRustFreeThinLTOData(&mut *(self.0 as *mut _));
         }
     }
 }
diff --git a/src/librustc_codegen_llvm/llvm/ffi.rs b/src/librustc_codegen_llvm/llvm/ffi.rs
index ce10a98938e..ba37eaa4608 100644
--- a/src/librustc_codegen_llvm/llvm/ffi.rs
+++ b/src/librustc_codegen_llvm/llvm/ffi.rs
@@ -1580,24 +1580,24 @@ extern "C" {
         NumModules: c_uint,
         PreservedSymbols: *const *const c_char,
         PreservedSymbolsLen: c_uint,
-    ) -> *mut ThinLTOData;
+    ) -> Option<&'static mut ThinLTOData>;
     pub fn LLVMRustPrepareThinLTORename(
-        Data: *const ThinLTOData,
+        Data: &ThinLTOData,
         Module: &Module,
     ) -> bool;
     pub fn LLVMRustPrepareThinLTOResolveWeak(
-        Data: *const ThinLTOData,
+        Data: &ThinLTOData,
         Module: &Module,
     ) -> bool;
     pub fn LLVMRustPrepareThinLTOInternalize(
-        Data: *const ThinLTOData,
+        Data: &ThinLTOData,
         Module: &Module,
     ) -> bool;
     pub fn LLVMRustPrepareThinLTOImport(
-        Data: *const ThinLTOData,
+        Data: &ThinLTOData,
         Module: &Module,
     ) -> bool;
-    pub fn LLVMRustFreeThinLTOData(Data: *mut ThinLTOData);
+    pub fn LLVMRustFreeThinLTOData(Data: &'static mut ThinLTOData);
     pub fn LLVMRustParseBitcodeForThinLTO(
         Context: &Context,
         Data: *const u8,