]> git.lizzy.rs Git - rust.git/commitdiff
rename tests: undefined -> uninit
authorRalf Jung <post@ralfj.de>
Mon, 27 Apr 2020 10:27:56 +0000 (12:27 +0200)
committerRalf Jung <post@ralfj.de>
Mon, 27 Apr 2020 10:32:03 +0000 (12:32 +0200)
tests/compile-fail/overwriting_part_of_relocation_makes_the_rest_undefined.rs [deleted file]
tests/compile-fail/overwriting_part_of_relocation_makes_the_rest_uninit.rs [new file with mode: 0644]
tests/compile-fail/transmute-pair-undef.rs [deleted file]
tests/compile-fail/transmute-pair-uninit.rs [new file with mode: 0644]
tests/compile-fail/undefined_buffer.rs [deleted file]
tests/compile-fail/undefined_byte_read.rs [deleted file]
tests/compile-fail/uninit_buffer.rs [new file with mode: 0644]
tests/compile-fail/uninit_byte_read.rs [new file with mode: 0644]
tests/run-pass/move-undef-primval.rs [deleted file]
tests/run-pass/move-uninit-primval.rs [new file with mode: 0644]

diff --git a/tests/compile-fail/overwriting_part_of_relocation_makes_the_rest_undefined.rs b/tests/compile-fail/overwriting_part_of_relocation_makes_the_rest_undefined.rs
deleted file mode 100644 (file)
index 3eab4c0..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-// Make sure we find these even with many checks disabled.
-// compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
-
-fn main() {
-    let mut p = &42;
-    unsafe {
-        let ptr: *mut _ = &mut p;
-        *(ptr as *mut u8) = 123; // if we ever support 8 bit pointers, this is gonna cause
-        // "attempted to interpret some raw bytes as a pointer address" instead of
-        // "attempted to read undefined bytes"
-    }
-    let x = *p; //~ ERROR this operation requires initialized memory
-    panic!("this should never print: {}", x);
-}
diff --git a/tests/compile-fail/overwriting_part_of_relocation_makes_the_rest_uninit.rs b/tests/compile-fail/overwriting_part_of_relocation_makes_the_rest_uninit.rs
new file mode 100644 (file)
index 0000000..3eab4c0
--- /dev/null
@@ -0,0 +1,14 @@
+// Make sure we find these even with many checks disabled.
+// compile-flags: -Zmiri-disable-alignment-check -Zmiri-disable-stacked-borrows -Zmiri-disable-validation
+
+fn main() {
+    let mut p = &42;
+    unsafe {
+        let ptr: *mut _ = &mut p;
+        *(ptr as *mut u8) = 123; // if we ever support 8 bit pointers, this is gonna cause
+        // "attempted to interpret some raw bytes as a pointer address" instead of
+        // "attempted to read undefined bytes"
+    }
+    let x = *p; //~ ERROR this operation requires initialized memory
+    panic!("this should never print: {}", x);
+}
diff --git a/tests/compile-fail/transmute-pair-undef.rs b/tests/compile-fail/transmute-pair-undef.rs
deleted file mode 100644 (file)
index 0f02697..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#![feature(core_intrinsics)]
-
-use std::mem;
-
-fn main() {
-    let x: Option<Box<[u8]>> = unsafe {
-        let z = std::intrinsics::add_with_overflow(0usize, 0usize);
-        std::mem::transmute::<(usize, bool), Option<Box<[u8]>>>(z)
-    };
-    let y = &x;
-    // Now read this bytewise. There should be (`ptr_size + 1`) def bytes followed by
-    // (`ptr_size - 1`) undef bytes (the padding after the bool) in there.
-    let z : *const u8 = y as *const _ as *const _;
-    let first_undef = mem::size_of::<usize>() as isize + 1;
-    for i in 0..first_undef {
-        let byte = unsafe { *z.offset(i) };
-        assert_eq!(byte, 0);
-    }
-    let v = unsafe { *z.offset(first_undef) };
-    if v == 0 {}
-    //~^ ERROR this operation requires initialized memory
-}
diff --git a/tests/compile-fail/transmute-pair-uninit.rs b/tests/compile-fail/transmute-pair-uninit.rs
new file mode 100644 (file)
index 0000000..0f02697
--- /dev/null
@@ -0,0 +1,22 @@
+#![feature(core_intrinsics)]
+
+use std::mem;
+
+fn main() {
+    let x: Option<Box<[u8]>> = unsafe {
+        let z = std::intrinsics::add_with_overflow(0usize, 0usize);
+        std::mem::transmute::<(usize, bool), Option<Box<[u8]>>>(z)
+    };
+    let y = &x;
+    // Now read this bytewise. There should be (`ptr_size + 1`) def bytes followed by
+    // (`ptr_size - 1`) undef bytes (the padding after the bool) in there.
+    let z : *const u8 = y as *const _ as *const _;
+    let first_undef = mem::size_of::<usize>() as isize + 1;
+    for i in 0..first_undef {
+        let byte = unsafe { *z.offset(i) };
+        assert_eq!(byte, 0);
+    }
+    let v = unsafe { *z.offset(first_undef) };
+    if v == 0 {}
+    //~^ ERROR this operation requires initialized memory
+}
diff --git a/tests/compile-fail/undefined_buffer.rs b/tests/compile-fail/undefined_buffer.rs
deleted file mode 100644 (file)
index dac02a8..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-// error-pattern: reading uninitialized memory
-
-use std::alloc::{alloc, dealloc, Layout};
-use std::slice::from_raw_parts;
-
-fn main() {
-    let layout = Layout::from_size_align(32, 8).unwrap();
-    unsafe {
-        let ptr = alloc(layout);
-        *ptr = 0x41;
-        *ptr.add(1) = 0x42;
-        *ptr.add(2) = 0x43;
-        *ptr.add(3) = 0x44;
-        *ptr.add(16) = 0x00;
-        let slice1 = from_raw_parts(ptr, 16);
-        let slice2 = from_raw_parts(ptr.add(16), 16);
-        drop(slice1.cmp(slice2));
-        dealloc(ptr, layout);
-    }
-}
diff --git a/tests/compile-fail/undefined_byte_read.rs b/tests/compile-fail/undefined_byte_read.rs
deleted file mode 100644 (file)
index 36c1413..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-fn main() {
-    let v: Vec<u8> = Vec::with_capacity(10);
-    let undef = unsafe { *v.get_unchecked(5) };
-    let x = undef + 1; //~ ERROR this operation requires initialized memory
-    panic!("this should never print: {}", x);
-}
diff --git a/tests/compile-fail/uninit_buffer.rs b/tests/compile-fail/uninit_buffer.rs
new file mode 100644 (file)
index 0000000..dac02a8
--- /dev/null
@@ -0,0 +1,20 @@
+// error-pattern: reading uninitialized memory
+
+use std::alloc::{alloc, dealloc, Layout};
+use std::slice::from_raw_parts;
+
+fn main() {
+    let layout = Layout::from_size_align(32, 8).unwrap();
+    unsafe {
+        let ptr = alloc(layout);
+        *ptr = 0x41;
+        *ptr.add(1) = 0x42;
+        *ptr.add(2) = 0x43;
+        *ptr.add(3) = 0x44;
+        *ptr.add(16) = 0x00;
+        let slice1 = from_raw_parts(ptr, 16);
+        let slice2 = from_raw_parts(ptr.add(16), 16);
+        drop(slice1.cmp(slice2));
+        dealloc(ptr, layout);
+    }
+}
diff --git a/tests/compile-fail/uninit_byte_read.rs b/tests/compile-fail/uninit_byte_read.rs
new file mode 100644 (file)
index 0000000..36c1413
--- /dev/null
@@ -0,0 +1,6 @@
+fn main() {
+    let v: Vec<u8> = Vec::with_capacity(10);
+    let undef = unsafe { *v.get_unchecked(5) };
+    let x = undef + 1; //~ ERROR this operation requires initialized memory
+    panic!("this should never print: {}", x);
+}
diff --git a/tests/run-pass/move-undef-primval.rs b/tests/run-pass/move-undef-primval.rs
deleted file mode 100644 (file)
index b8bd869..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#![allow(deprecated)]
-
-struct Foo {
-    _inner: i32,
-}
-
-fn main() {
-    unsafe {
-        let foo = Foo {
-            _inner: std::mem::uninitialized(),
-        };
-        let _bar = foo;
-    }
-}
diff --git a/tests/run-pass/move-uninit-primval.rs b/tests/run-pass/move-uninit-primval.rs
new file mode 100644 (file)
index 0000000..b8bd869
--- /dev/null
@@ -0,0 +1,14 @@
+#![allow(deprecated)]
+
+struct Foo {
+    _inner: i32,
+}
+
+fn main() {
+    unsafe {
+        let foo = Foo {
+            _inner: std::mem::uninitialized(),
+        };
+        let _bar = foo;
+    }
+}