about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Schneider <github35764891676564198441@oli-obk.de>2018-07-15 01:52:45 +0200
committerOliver Schneider <github35764891676564198441@oli-obk.de>2018-07-15 01:52:45 +0200
commitecab96fd7ce9991218145a9e0063ef3c25c7a977 (patch)
treed85bc6edd7eacb29f19a15443f15b8a3a86c8b74
parent1caa593cb6bd9a33eb625ad313010d2b141dea5c (diff)
downloadrust-ecab96fd7ce9991218145a9e0063ef3c25c7a977.tar.gz
rust-ecab96fd7ce9991218145a9e0063ef3c25c7a977.zip
Ubsan this newly discovered dead code
-rw-r--r--src/librustc_codegen_llvm/back/write.rs23
1 files changed, 9 insertions, 14 deletions
diff --git a/src/librustc_codegen_llvm/back/write.rs b/src/librustc_codegen_llvm/back/write.rs
index 0ffb83ff337..d36142af56c 100644
--- a/src/librustc_codegen_llvm/back/write.rs
+++ b/src/librustc_codegen_llvm/back/write.rs
@@ -399,10 +399,7 @@ impl CodegenContext {
 }
 
 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));
         }
     }
 }