Skip to content

Commit ecab96f

Browse files
committed
Ubsan this newly discovered dead code
1 parent 1caa593 commit ecab96f

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/librustc_codegen_llvm/back/write.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -399,35 +399,30 @@ impl CodegenContext {
399399
}
400400

401401
struct DiagnosticHandlers<'a> {
402-
#[allow(dead_code)]
403-
// This value is not actually dead, llcx has pointers to it and needs these pointers to be alive
404-
// until Drop is executed on this object
405-
inner: Box<(&'a CodegenContext, &'a Handler)>,
402+
data: *mut (&'a CodegenContext, &'a Handler),
406403
llcx: ContextRef,
407404
}
408405

409406
impl<'a> DiagnosticHandlers<'a> {
410407
fn new(cgcx: &'a CodegenContext,
411408
handler: &'a Handler,
412409
llcx: ContextRef) -> DiagnosticHandlers<'a> {
413-
let data = Box::new((cgcx, handler));
410+
let data = Box::into_raw(Box::new((cgcx, handler)));
414411
unsafe {
415-
let arg = &*data as &(_, _) as *const _ as *mut _;
416-
llvm::LLVMRustSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, arg);
417-
llvm::LLVMContextSetDiagnosticHandler(llcx, diagnostic_handler, arg);
418-
}
419-
DiagnosticHandlers {
420-
inner: data,
421-
llcx: llcx,
412+
llvm::LLVMRustSetInlineAsmDiagnosticHandler(llcx, inline_asm_handler, data as *mut _);
413+
llvm::LLVMContextSetDiagnosticHandler(llcx, diagnostic_handler, data as *mut _);
422414
}
415+
DiagnosticHandlers { data, llcx }
423416
}
424417
}
425418

426419
impl<'a> Drop for DiagnosticHandlers<'a> {
427420
fn drop(&mut self) {
421+
use std::ptr::null_mut;
428422
unsafe {
429-
llvm::LLVMRustSetInlineAsmDiagnosticHandler(self.llcx, inline_asm_handler, 0 as *mut _);
430-
llvm::LLVMContextSetDiagnosticHandler(self.llcx, diagnostic_handler, 0 as *mut _);
423+
llvm::LLVMRustSetInlineAsmDiagnosticHandler(self.llcx, inline_asm_handler, null_mut());
424+
llvm::LLVMContextSetDiagnosticHandler(self.llcx, diagnostic_handler, null_mut());
425+
drop(Box::from_raw(self.data));
431426
}
432427
}
433428
}

0 commit comments

Comments
 (0)