1
Fork 0

Make allocator shim creation mostly use safe code

This commit is contained in:
Oli Scherer 2025-02-24 11:14:21 +00:00
parent 840e31b29f
commit 396baa750e
5 changed files with 91 additions and 93 deletions

View file

@ -29,6 +29,7 @@ use std::mem::ManuallyDrop;
use back::owned_target_machine::OwnedTargetMachine;
use back::write::{create_informational_target_machine, create_target_machine};
use context::SimpleCx;
use errors::{AutoDiffWithoutLTO, ParseTargetMachineConfig};
pub(crate) use llvm_util::target_features_cfg;
use rustc_ast::expand::allocator::AllocatorKind;
@ -116,9 +117,11 @@ impl ExtraBackendMethods for LlvmCodegenBackend {
kind: AllocatorKind,
alloc_error_handler_kind: AllocatorKind,
) -> ModuleLlvm {
let mut module_llvm = ModuleLlvm::new_metadata(tcx, module_name);
let module_llvm = ModuleLlvm::new_metadata(tcx, module_name);
let cx =
SimpleCx::new(module_llvm.llmod(), &module_llvm.llcx, tcx.data_layout.pointer_size);
unsafe {
allocator::codegen(tcx, &mut module_llvm, module_name, kind, alloc_error_handler_kind);
allocator::codegen(tcx, cx, module_name, kind, alloc_error_handler_kind);
}
module_llvm
}