Skip to content

Commit 244ea12

Browse files
committed
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.
1 parent 96be6ef commit 244ea12

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl WriteBackendMethods for GccCodegenBackend {
391391
unimplemented!()
392392
}
393393

394-
unsafe fn optimize(
394+
fn optimize(
395395
_cgcx: &CodegenContext<Self>,
396396
_dcx: DiagCtxtHandle<'_>,
397397
module: &mut ModuleCodegen<Self::Module>,
@@ -409,14 +409,14 @@ impl WriteBackendMethods for GccCodegenBackend {
409409
Ok(())
410410
}
411411

412-
unsafe fn optimize_thin(
412+
fn optimize_thin(
413413
cgcx: &CodegenContext<Self>,
414414
thin: ThinModule<Self>,
415415
) -> Result<ModuleCodegen<Self::Module>, FatalError> {
416416
back::lto::optimize_thin_module(thin, cgcx)
417417
}
418418

419-
unsafe fn codegen(
419+
fn codegen(
420420
cgcx: &CodegenContext<Self>,
421421
dcx: DiagCtxtHandle<'_>,
422422
module: ModuleCodegen<Self::Module>,

0 commit comments

Comments
 (0)