about summary refs log tree commit diff
path: root/src
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 /src
parent10c4c4afec6dfc483af6efb7019941bab9a51a29 (diff)
downloadrust-aa6795e2d4cdae6af2ea854744c3bec2eb30d16e.tar.gz
rust-aa6795e2d4cdae6af2ea854744c3bec2eb30d16e.zip
Add `intrinsics::const_deallocate`
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/consts/const-eval/heap/dealloc_intrinsic.rs12
-rw-r--r--src/test/ui/consts/const-eval/heap/dealloc_intrinsic_dangling.rs22
-rw-r--r--src/test/ui/consts/const-eval/heap/dealloc_intrinsic_dangling.stderr15
-rw-r--r--src/test/ui/consts/const-eval/heap/dealloc_intrinsic_duplicate.rs13
-rw-r--r--src/test/ui/consts/const-eval/heap/dealloc_intrinsic_duplicate.stderr9
-rw-r--r--src/test/ui/consts/const-eval/heap/dealloc_intrinsic_incorrect_layout.rs29
-rw-r--r--src/test/ui/consts/const-eval/heap/dealloc_intrinsic_incorrect_layout.stderr27
7 files changed, 127 insertions, 0 deletions
diff --git a/src/test/ui/consts/const-eval/heap/dealloc_intrinsic.rs b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic.rs
new file mode 100644
index 00000000000..b7c2b752644
--- /dev/null
+++ b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic.rs
@@ -0,0 +1,12 @@
+// run-pass
+#![feature(core_intrinsics)]
+#![feature(const_heap)]
+
+use std::intrinsics;
+
+const _X: () = unsafe {
+    let ptr = intrinsics::const_allocate(4, 4);
+    intrinsics::const_deallocate(ptr, 4, 4);
+};
+
+fn main() {}
diff --git a/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_dangling.rs b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_dangling.rs
new file mode 100644
index 00000000000..b6d89a58dce
--- /dev/null
+++ b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_dangling.rs
@@ -0,0 +1,22 @@
+#![feature(core_intrinsics)]
+#![feature(const_heap)]
+#![feature(const_mut_refs)]
+
+use std::intrinsics;
+
+const _X: &'static u8 = unsafe {
+    let ptr = intrinsics::const_allocate(4, 4);
+    intrinsics::const_deallocate(ptr, 4, 4);
+    &*ptr
+    //~^ error: evaluation of constant value failed
+};
+
+const _Y: u8 = unsafe {
+    let ptr = intrinsics::const_allocate(4, 4);
+    let reference = &*ptr;
+    intrinsics::const_deallocate(ptr, 4, 4);
+    *reference
+    //~^ error: evaluation of constant value failed
+};
+
+fn main() {}
diff --git a/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_dangling.stderr b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_dangling.stderr
new file mode 100644
index 00000000000..4eb1c42e1f7
--- /dev/null
+++ b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_dangling.stderr
@@ -0,0 +1,15 @@
+error[E0080]: evaluation of constant value failed
+  --> $DIR/dealloc_intrinsic_dangling.rs:10:5
+   |
+LL |     &*ptr
+   |     ^^^^^ pointer to alloc2 was dereferenced after this allocation got freed
+
+error[E0080]: evaluation of constant value failed
+  --> $DIR/dealloc_intrinsic_dangling.rs:18:5
+   |
+LL |     *reference
+   |     ^^^^^^^^^^ pointer to alloc4 was dereferenced after this allocation got freed
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_duplicate.rs b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_duplicate.rs
new file mode 100644
index 00000000000..4010b476990
--- /dev/null
+++ b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_duplicate.rs
@@ -0,0 +1,13 @@
+#![feature(core_intrinsics)]
+#![feature(const_heap)]
+
+use std::intrinsics;
+
+const _X: () = unsafe {
+    let ptr = intrinsics::const_allocate(4, 4);
+    intrinsics::const_deallocate(ptr, 4, 4);
+    intrinsics::const_deallocate(ptr, 4, 4);
+    //~^ error: evaluation of constant value failed
+};
+
+fn main() {}
diff --git a/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_duplicate.stderr b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_duplicate.stderr
new file mode 100644
index 00000000000..8177a08504b
--- /dev/null
+++ b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_duplicate.stderr
@@ -0,0 +1,9 @@
+error[E0080]: evaluation of constant value failed
+  --> $DIR/dealloc_intrinsic_duplicate.rs:9:5
+   |
+LL |     intrinsics::const_deallocate(ptr, 4, 4);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pointer to alloc2 was dereferenced after this allocation got freed
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_incorrect_layout.rs b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_incorrect_layout.rs
new file mode 100644
index 00000000000..031d70fdc88
--- /dev/null
+++ b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_incorrect_layout.rs
@@ -0,0 +1,29 @@
+#![feature(core_intrinsics)]
+#![feature(const_heap)]
+
+use std::intrinsics;
+
+const _X: () = unsafe {
+    let ptr = intrinsics::const_allocate(4, 4);
+    intrinsics::const_deallocate(ptr, 4, 2);
+    //~^ error: evaluation of constant value failed
+};
+const _Y: () = unsafe {
+    let ptr = intrinsics::const_allocate(4, 4);
+    intrinsics::const_deallocate(ptr, 2, 4);
+    //~^ error: evaluation of constant value failed
+};
+
+const _Z: () = unsafe {
+    let ptr = intrinsics::const_allocate(4, 4);
+    intrinsics::const_deallocate(ptr, 3, 4);
+    //~^ error: evaluation of constant value failed
+};
+
+const _W: () = unsafe {
+    let ptr = intrinsics::const_allocate(4, 4);
+    intrinsics::const_deallocate(ptr, 4, 3);
+    //~^ error: evaluation of constant value failed
+};
+
+fn main() {}
diff --git a/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_incorrect_layout.stderr b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_incorrect_layout.stderr
new file mode 100644
index 00000000000..650b409b190
--- /dev/null
+++ b/src/test/ui/consts/const-eval/heap/dealloc_intrinsic_incorrect_layout.stderr
@@ -0,0 +1,27 @@
+error[E0080]: evaluation of constant value failed
+  --> $DIR/dealloc_intrinsic_incorrect_layout.rs:8:5
+   |
+LL |     intrinsics::const_deallocate(ptr, 4, 2);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: alloc2 has size 4 and alignment 4, but gave size 4 and alignment 2
+
+error[E0080]: evaluation of constant value failed
+  --> $DIR/dealloc_intrinsic_incorrect_layout.rs:13:5
+   |
+LL |     intrinsics::const_deallocate(ptr, 2, 4);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: alloc4 has size 4 and alignment 4, but gave size 2 and alignment 4
+
+error[E0080]: evaluation of constant value failed
+  --> $DIR/dealloc_intrinsic_incorrect_layout.rs:19:5
+   |
+LL |     intrinsics::const_deallocate(ptr, 3, 4);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: alloc6 has size 4 and alignment 4, but gave size 3 and alignment 4
+
+error[E0080]: evaluation of constant value failed
+  --> $DIR/dealloc_intrinsic_incorrect_layout.rs:25:5
+   |
+LL |     intrinsics::const_deallocate(ptr, 4, 3);
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ align has to be a power of 2, `3` is not a power of 2
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0080`.