Mark all optimize methods and the codegen method as safe

There is no safety contract and I don't think any of them can actually
cause UB in more ways than passing malicious source code to rustc can.
While LtoModuleCodegen::optimize says that the returned ModuleCodegen
points into the LTO module, the LTO module has already been dropped by
the time this function returns, so if the returned ModuleCodegen indeed
points into the LTO module, we would have seen crashes on every LTO
compilation, which we don't. As such the comment is outdated.
This commit is contained in:
bjorn3
2025-01-09 18:41:19 +00:00
parent d7c0bde0c1
commit f0707fad31
7 changed files with 25 additions and 34 deletions

View File

@@ -799,7 +799,7 @@ impl Drop for ThinBuffer {
}
}
pub(crate) unsafe fn optimize_thin_module(
pub(crate) fn optimize_thin_module(
thin_module: ThinModule<LlvmCodegenBackend>,
cgcx: &CodegenContext<LlvmCodegenBackend>,
) -> Result<ModuleCodegen<ModuleLlvm>, FatalError> {

View File

@@ -704,7 +704,7 @@ pub(crate) unsafe fn llvm_optimize(
}
// Unsafe due to LLVM calls.
pub(crate) unsafe fn optimize(
pub(crate) fn optimize(
cgcx: &CodegenContext<LlvmCodegenBackend>,
dcx: DiagCtxtHandle<'_>,
module: &mut ModuleCodegen<ModuleLlvm>,
@@ -815,7 +815,7 @@ pub(crate) fn link(
Ok(modules.remove(0))
}
pub(crate) unsafe fn codegen(
pub(crate) fn codegen(
cgcx: &CodegenContext<LlvmCodegenBackend>,
dcx: DiagCtxtHandle<'_>,
module: ModuleCodegen<ModuleLlvm>,