]> git.lizzy.rs Git - rust.git/commitdiff
rustc_codegen_llvm: use safe references for ThinLTOData.
authorIrina Popa <irinagpopa@gmail.com>
Tue, 17 Jul 2018 13:43:49 +0000 (16:43 +0300)
committerIrina Popa <irinagpopa@gmail.com>
Mon, 30 Jul 2018 17:34:51 +0000 (20:34 +0300)
src/librustc_codegen_llvm/back/lto.rs
src/librustc_codegen_llvm/llvm/ffi.rs

index ce56be734d77595a58b55eb6e997b5bc51a2636c..daa2fb05280649793a50ac3831c7352cd8b1f5df 100644 (file)
@@ -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 _));
         }
     }
 }
index ce10a98938ec206a2814c79125faf79ff1a16edb..ba37eaa4608ba7cbd5104e860d7ce131563888f7 100644 (file)
@@ -1580,24 +1580,24 @@ pub fn LLVMRustCreateThinLTOData(
         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,