about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/const_eval
diff options
context:
space:
mode:
authorwoppopo <woppopo@protonmail.com>2021-12-25 22:35:11 +0900
committerwoppopo <woppopo@protonmail.com>2022-01-23 15:13:44 +0900
commitaa6795e2d4cdae6af2ea854744c3bec2eb30d16e (patch)
tree12660e39d70a67da072f45f3e3bee29a04020979 /compiler/rustc_const_eval/src/const_eval
parent10c4c4afec6dfc483af6efb7019941bab9a51a29 (diff)
downloadrust-aa6795e2d4cdae6af2ea854744c3bec2eb30d16e.tar.gz
rust-aa6795e2d4cdae6af2ea854744c3bec2eb30d16e.zip
Add `intrinsics::const_deallocate`
Diffstat (limited to 'compiler/rustc_const_eval/src/const_eval')
-rw-r--r--compiler/rustc_const_eval/src/const_eval/machine.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs
index 30e9cbe4403..62eaf333340 100644
--- a/compiler/rustc_const_eval/src/const_eval/machine.rs
+++ b/compiler/rustc_const_eval/src/const_eval/machine.rs
@@ -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 `{}`",