const_deallocate
: Don't deallocate memory allocated in an another const. Does nothing at runtime.
`const_allocate`: Returns a null pointer at runtime.
This commit is contained in:
parent
aa6795e2d4
commit
29932db09b
8 changed files with 69 additions and 11 deletions
|
@ -369,6 +369,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
}
|
||||
}
|
||||
|
||||
sym::const_allocate => {
|
||||
// returns a null pointer at runtime.
|
||||
bx.const_null(bx.type_i8p())
|
||||
}
|
||||
|
||||
sym::const_deallocate => {
|
||||
// nop at runtime.
|
||||
return;
|
||||
}
|
||||
|
||||
// This requires that atomic intrinsics follow a specific naming pattern:
|
||||
// "atomic_<operation>[_<ordering>]", and no ordering means SeqCst
|
||||
name if name_str.starts_with("atomic_") => {
|
||||
|
|
|
@ -358,11 +358,21 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
|
|||
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),
|
||||
)?;
|
||||
// If an allocation is created in an another const,
|
||||
// we don't deallocate it.
|
||||
let (alloc_id, _, _) = ecx.memory.ptr_get_alloc(ptr)?;
|
||||
let is_allocated_in_another_const = matches!(
|
||||
ecx.tcx.get_global_alloc(alloc_id),
|
||||
Some(interpret::GlobalAlloc::Memory(_))
|
||||
);
|
||||
|
||||
if !is_allocated_in_another_const {
|
||||
ecx.memory.deallocate(
|
||||
ptr,
|
||||
Some((size, align)),
|
||||
interpret::MemoryKind::Machine(MemoryKind::Heap),
|
||||
)?;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
return Err(ConstEvalErrKind::NeedsRfc(format!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue