+++ /dev/null
-// 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);
-}
--- /dev/null
+// 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);
+}
+++ /dev/null
-#![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
-}
--- /dev/null
+#![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
+}
+++ /dev/null
-// 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);
- }
-}
+++ /dev/null
-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);
-}
--- /dev/null
+// 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);
+ }
+}
--- /dev/null
+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);
+}
+++ /dev/null
-#![allow(deprecated)]
-
-struct Foo {
- _inner: i32,
-}
-
-fn main() {
- unsafe {
- let foo = Foo {
- _inner: std::mem::uninitialized(),
- };
- let _bar = foo;
- }
-}
--- /dev/null
+#![allow(deprecated)]
+
+struct Foo {
+ _inner: i32,
+}
+
+fn main() {
+ unsafe {
+ let foo = Foo {
+ _inner: std::mem::uninitialized(),
+ };
+ let _bar = foo;
+ }
+}