]> git.lizzy.rs Git - rust.git/commitdiff
Ubsan this newly discovered dead code
authorOliver Schneider <github35764891676564198441@oli-obk.de>
Sat, 14 Jul 2018 23:52:45 +0000 (01:52 +0200)
committerOliver Schneider <github35764891676564198441@oli-obk.de>
Sat, 14 Jul 2018 23:52:45 +0000 (01:52 +0200)
src/librustc_codegen_llvm/back/write.rs

index 0ffb83ff3378913172c7282047e86903df6dd49f..d36142af56c6540ad15af51d052e1bace989f8c9 100644 (file)
@@ -399,10 +399,7 @@ pub(crate) fn save_temp_bitcode(&self, module: &ModuleCodegen, name: &str) {
 }
 
 struct DiagnosticHandlers<'a> {
-    #[allow(dead_code)]
-    // This value is not actually dead, llcx has pointers to it and needs these pointers to be alive
-    // until Drop is executed on this object
-    inner: Box<(&'a CodegenContext, &'a Handler)>,
+    data: *mut (&'a CodegenContext, &'a Handler),
     llcx: ContextRef,
 }
 
@@ -410,24 +407,22 @@ impl<'a> DiagnosticHandlers<'a> {
     fn new(cgcx: &'a CodegenContext,
            handler: &'a Handler,
            llcx: ContextRef) -> DiagnosticHandlers<'a> {
-        let data = Box::new((cgcx, handler));
+        let data = Box::into_raw(Box::new((cgcx, handler)));
         unsafe {
-            let arg = &*data as &(_, _) as *const _ as *mut _;
-            llvm::LLVMRustSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, arg);
-            llvm::LLVMContextSetDiagnosticHandler(llcx, diagnostic_handler, arg);
-        }
-        DiagnosticHandlers {
-            inner: data,
-            llcx: llcx,
+            llvm::LLVMRustSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, data as *mut _);
+            llvm::LLVMContextSetDiagnosticHandler(llcx, diagnostic_handler, data as *mut _);
         }
+        DiagnosticHandlers { data, llcx }
     }
 }
 
 impl<'a> Drop for DiagnosticHandlers<'a> {
     fn drop(&mut self) {
+        use std::ptr::null_mut;
         unsafe {
-            llvm::LLVMRustSetInlineAsmDiagnosticHandler(self.llcx, inline_asm_handler, 0 as *mut _);
-            llvm::LLVMContextSetDiagnosticHandler(self.llcx, diagnostic_handler, 0 as *mut _);
+            llvm::LLVMRustSetInlineAsmDiagnosticHandler(self.llcx, inline_asm_handler, null_mut());
+            llvm::LLVMContextSetDiagnosticHandler(self.llcx, diagnostic_handler, null_mut());
+            drop(Box::from_raw(self.data));
         }
     }
 }