Skip to content

Commit 894467e

Browse files
committed
rustc_codegen_llvm: use safe references for Linker.
1 parent 2c1d7fb commit 894467e

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/librustc_codegen_llvm/back/lto.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,10 @@ fn fat_lto(cgcx: &CodegenContext,
294294
}])
295295
}
296296

297-
struct Linker(llvm::LinkerRef);
297+
struct Linker<'a>(&'a mut llvm::Linker<'a>);
298298

299-
impl Linker {
300-
fn new(llmod: &llvm::Module) -> Linker {
299+
impl Linker<'a> {
300+
fn new(llmod: &'a llvm::Module) -> Self {
301301
unsafe { Linker(llvm::LLVMRustLinkerNew(llmod)) }
302302
}
303303

@@ -314,9 +314,9 @@ impl Linker {
314314
}
315315
}
316316

317-
impl Drop for Linker {
317+
impl Drop for Linker<'a> {
318318
fn drop(&mut self) {
319-
unsafe { llvm::LLVMRustLinkerFree(self.0); }
319+
unsafe { llvm::LLVMRustLinkerFree(&mut *(self.0 as *mut _)); }
320320
}
321321
}
322322

src/librustc_codegen_llvm/llvm/ffi.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,7 @@ extern { pub type SMDiagnostic; }
414414
extern { pub type RustArchiveMember; }
415415
pub type RustArchiveMemberRef = *mut RustArchiveMember;
416416
pub struct OperandBundleDef<'a>(InvariantOpaque<'a>);
417-
extern { pub type Linker; }
418-
pub type LinkerRef = *mut Linker;
417+
pub struct Linker<'a>(InvariantOpaque<'a>);
419418

420419
pub type DiagnosticHandler = unsafe extern "C" fn(&DiagnosticInfo, *mut c_void);
421420
pub type InlineAsmDiagHandler = unsafe extern "C" fn(&SMDiagnostic, *const c_void, c_uint);
@@ -1580,9 +1579,9 @@ extern "C" {
15801579
CU2: &mut *mut c_void);
15811580
pub fn LLVMRustThinLTOPatchDICompileUnit(M: &Module, CU: *mut c_void);
15821581

1583-
pub fn LLVMRustLinkerNew(M: &Module) -> LinkerRef;
1584-
pub fn LLVMRustLinkerAdd(linker: LinkerRef,
1582+
pub fn LLVMRustLinkerNew(M: &'a Module) -> &'a mut Linker<'a>;
1583+
pub fn LLVMRustLinkerAdd(linker: &Linker,
15851584
bytecode: *const c_char,
15861585
bytecode_len: usize) -> bool;
1587-
pub fn LLVMRustLinkerFree(linker: LinkerRef);
1586+
pub fn LLVMRustLinkerFree(linker: &'a mut Linker<'a>);
15881587
}

0 commit comments

Comments
 (0)