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

3 files changed

Lines changed: 3 additions & 8 deletions

File tree

‎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)fnLLVMDisposeTargetMachine(T: ptr::NonNull<TargetMachine>);
1057+
10561058
// Create modules.
10571059
pub(crate)fnLLVMModuleCreateWithNameInContext(
10581060
ModuleID:*constc_char,
@@ -2499,7 +2501,6 @@ unsafe extern "C" {
24992501
UseWasmEH:bool,
25002502
) -> *mutTargetMachine;
25012503

2502-
pub(crate)fnLLVMRustDisposeTargetMachine(T:*mutTargetMachine);
25032504
pub(crate)fnLLVMRustAddLibraryInfo<'a>(
25042505
PM:&PassManager<'a>,
25052506
M:&'aModule,

‎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
returnwrap(TM);
360360
}
361361

362-
extern"C"voidLLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
363-
deleteunwrap(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"voidLLVMRustAddLibraryInfo(LLVMPassManagerRef PMR, LLVMModuleRef M,

0 commit comments

Comments
 (0)