Skip to content

Commit 59866ef

Browse files
authored
Rollup merge of #147015 - Zalathar:dispose-tm, r=lqd
Use `LLVMDisposeTargetMachine` After bumping the minimum LLVM version to 20 (#145071), we no longer need to run any custom code when disposing of a TargetMachine, so we can just use the upstream LLVM-C function.
2 parents a632541 + 85018f0 commit 59866ef

File tree

3 files changed

+3
-8
lines changed

3 files changed

+3
-8
lines changed

compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ impl Drop for OwnedTargetMachine {
9595
// SAFETY: constructing ensures we have a valid pointer created by
9696
// llvm::LLVMRustCreateTargetMachine OwnedTargetMachine is not copyable so there is no
9797
// double free or use after free.
98-
unsafe {
99-
llvm::LLVMRustDisposeTargetMachine(self.tm_unique.as_ptr());
100-
}
98+
unsafe { llvm::LLVMDisposeTargetMachine(self.tm_unique) };
10199
}
102100
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,8 @@ unsafe extern "C" {
10531053
SLen: c_uint,
10541054
) -> MetadataKindId;
10551055

1056+
pub(crate) fn LLVMDisposeTargetMachine(T: ptr::NonNull<TargetMachine>);
1057+
10561058
// Create modules.
10571059
pub(crate) fn LLVMModuleCreateWithNameInContext(
10581060
ModuleID: *const c_char,
@@ -2499,7 +2501,6 @@ unsafe extern "C" {
24992501
UseWasmEH: bool,
25002502
) -> *mut TargetMachine;
25012503

2502-
pub(crate) fn LLVMRustDisposeTargetMachine(T: *mut TargetMachine);
25032504
pub(crate) fn LLVMRustAddLibraryInfo<'a>(
25042505
PM: &PassManager<'a>,
25052506
M: &'a Module,

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,6 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
359359
return wrap(TM);
360360
}
361361

362-
extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
363-
delete unwrap(TM);
364-
}
365-
366362
// Unfortunately, the LLVM C API doesn't provide a way to create the
367363
// TargetLibraryInfo pass, so we use this method to do so.
368364
extern "C" void LLVMRustAddLibraryInfo(LLVMPassManagerRef PMR, LLVMModuleRef M,

0 commit comments

Comments
 (0)