Add intrinsics::const_deallocate
This commit is contained in:
parent
10c4c4afec
commit
aa6795e2d4
11 changed files with 156 additions and 0 deletions
|
@ -347,6 +347,23 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||
)?;
|
||||
ecx.write_pointer(ptr, dest)?;
|
||||
}
|
||||
sym::const_deallocate => {
|
||||
let ptr = ecx.read_pointer(&args[0])?;
|
||||
let size = ecx.read_scalar(&args[1])?.to_machine_usize(ecx)?;
|
||||
let align = ecx.read_scalar(&args[2])?.to_machine_usize(ecx)?;
|
||||
|
||||
let size = Size::from_bytes(size);
|
||||
let align = match Align::from_bytes(align) {
|
||||
Ok(a) => a,
|
||||
Err(err) => throw_ub_format!("align has to be a power of 2, {}", err),
|
||||
};
|
||||
|
||||
ecx.memory.deallocate(
|
||||
ptr,
|
||||
Some((size, align)),
|
||||
interpret::MemoryKind::Machine(MemoryKind::Heap),
|
||||
)?;
|
||||
}
|
||||
_ => {
|
||||
return Err(ConstEvalErrKind::NeedsRfc(format!(
|
||||
"calling intrinsic `{}`",
|
||||
|
|
|
@ -460,6 +460,7 @@ symbols! {
|
|||
const_async_blocks,
|
||||
const_compare_raw_pointers,
|
||||
const_constructor,
|
||||
const_deallocate,
|
||||
const_eval_limit,
|
||||
const_eval_select,
|
||||
const_eval_select_ct,
|
||||
|
|
|
@ -297,6 +297,11 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
|
|||
sym::const_allocate => {
|
||||
(0, vec![tcx.types.usize, tcx.types.usize], tcx.mk_mut_ptr(tcx.types.u8))
|
||||
}
|
||||
sym::const_deallocate => (
|
||||
0,
|
||||
vec![tcx.mk_mut_ptr(tcx.types.u8), tcx.types.usize, tcx.types.usize],
|
||||
tcx.mk_unit(),
|
||||
),
|
||||
|
||||
sym::ptr_offset_from => {
|
||||
(1, vec![tcx.mk_imm_ptr(param(0)), tcx.mk_imm_ptr(param(0))], tcx.types.isize)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue