run_tests("compile-fail", path, target, flags);
}
-fn miri_pass(path: &str, target: &str, opt: bool, noseed: bool) {
+fn miri_pass(path: &str, target: &str, opt: bool) {
let opt_str = if opt { " with optimizations" } else { "" };
eprintln!("{}", format!(
"## Running run-pass tests in {} against miri for target {}{}",
let mut flags = Vec::new();
if opt {
flags.push("-Zmir-opt-level=3".to_owned());
- } else if !noseed {
- // Run with intptrcast. Avoid test matrix explosion by doing either this or opt-level=3.
- flags.push("-Zmiri-seed=".to_owned());
}
run_tests("ui", path, target, flags);
}
fn run_pass_miri(opt: bool) {
- miri_pass("tests/run-pass", &get_target(), opt, false);
- miri_pass("tests/run-pass-noseed", &get_target(), opt, true);
+ miri_pass("tests/run-pass", &get_target(), opt);
}
fn compile_fail_miri(opt: bool) {
+++ /dev/null
-// compile-flags: -Zmiri-seed=0000000000000000
-
-use std::collections::{self, HashMap};
-use std::hash::{BuildHasherDefault, BuildHasher};
-
-fn test_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
- map.insert(0, 0);
- assert_eq!(map.values().fold(0, |x, y| x+y), 0);
-
- let num = 25;
- for i in 1..num {
- map.insert(i, i);
- }
- assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2); // check the right things are in the table now
-
- // Inserting again replaces the existing entries
- for i in 0..num {
- map.insert(i, num-1-i);
- }
- assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2);
-
- // TODO: Test Entry API, Iterators, ...
-
-}
-
-fn main() {
- if cfg!(target_os = "macos") { // TODO: Implement libstd HashMap seeding for macOS (https://github.com/rust-lang/miri/issues/686).
- // Until then, use a deterministic map.
- test_map::<BuildHasherDefault<collections::hash_map::DefaultHasher>>(HashMap::default());
- } else {
- test_map(HashMap::new());
- }
-}
+++ /dev/null
-// compile-flags: -Zmiri-seed=
-#![feature(allocator_api)]
-
-use std::ptr::NonNull;
-use std::alloc::{Global, Alloc, Layout, System};
-use std::slice;
-
-fn check_alloc<T: Alloc>(mut allocator: T) { unsafe {
- for &align in &[4, 8, 16, 32] {
- let layout = Layout::from_size_align(20, align).unwrap();
-
- for _ in 0..32 {
- let a = allocator.alloc(layout).unwrap();
- assert_eq!(a.as_ptr() as usize % align, 0, "pointer is incorrectly aligned");
- allocator.dealloc(a, layout);
- }
-
- let p1 = allocator.alloc_zeroed(layout).unwrap();
- assert_eq!(p1.as_ptr() as usize % align, 0, "pointer is incorrectly aligned");
-
- let p2 = allocator.realloc(p1, layout, 40).unwrap();
- let layout = Layout::from_size_align(40, align).unwrap();
- assert_eq!(p2.as_ptr() as usize % align, 0, "pointer is incorrectly aligned");
- let slice = slice::from_raw_parts(p2.as_ptr(), 20);
- assert_eq!(&slice, &[0_u8; 20]);
-
- // old size == new size
- let p3 = allocator.realloc(p2, layout, 40).unwrap();
- assert_eq!(p3.as_ptr() as usize % align, 0, "pointer is incorrectly aligned");
- let slice = slice::from_raw_parts(p3.as_ptr(), 20);
- assert_eq!(&slice, &[0_u8; 20]);
-
- // old size > new size
- let p4 = allocator.realloc(p3, layout, 10).unwrap();
- let layout = Layout::from_size_align(10, align).unwrap();
- assert_eq!(p4.as_ptr() as usize % align, 0, "pointer is incorrectly aligned");
- let slice = slice::from_raw_parts(p4.as_ptr(), 10);
- assert_eq!(&slice, &[0_u8; 10]);
-
- allocator.dealloc(p4, layout);
- }
-} }
-
-fn check_align_requests<T: Alloc>(mut allocator: T) {
- for &size in &[2, 8, 64] { // size less than and bigger than alignment
- for &align in &[4, 8, 16, 32] { // Be sure to cover less than and bigger than `MIN_ALIGN` for all architectures
- let iterations = 32;
- unsafe {
- let pointers: Vec<_> = (0..iterations).map(|_| {
- allocator.alloc(Layout::from_size_align(size, align).unwrap()).unwrap()
- }).collect();
- for &ptr in &pointers {
- assert_eq!((ptr.as_ptr() as usize) % align, 0,
- "Got a pointer less aligned than requested")
- }
-
- // Clean up.
- for &ptr in &pointers {
- allocator.dealloc(ptr, Layout::from_size_align(size, align).unwrap())
- }
- }
- }
- }
-}
-
-fn global_to_box() {
- type T = [i32; 4];
- let l = Layout::new::<T>();
- // allocate manually with global allocator, then turn into Box and free there
- unsafe {
- let ptr = Global.alloc(l).unwrap().as_ptr() as *mut T;
- let b = Box::from_raw(ptr);
- drop(b);
- }
-}
-
-fn box_to_global() {
- type T = [i32; 4];
- let l = Layout::new::<T>();
- // allocate with the Box, then deallocate manually with global allocator
- unsafe {
- let b = Box::new(T::default());
- let ptr = Box::into_raw(b);
- Global.dealloc(NonNull::new(ptr as *mut u8).unwrap(), l);
- }
-}
-
-fn main() {
- check_alloc(System);
- check_alloc(Global);
- check_align_requests(System);
- check_align_requests(Global);
- global_to_box();
- box_to_global();
-}
+++ /dev/null
-// compile-flags: -Zmiri-seed=0000000000000000
-
-// This returns a miri pointer at type usize, if the argument is a proper pointer
-fn transmute_ptr_to_int<T>(x: *const T) -> usize {
- unsafe { std::mem::transmute(x) }
-}
-
-fn main() {
- // Some casting-to-int with arithmetic.
- let x = &42 as *const i32 as usize;
- let y = x * 2;
- assert_eq!(y, x + x);
- let z = y as u8 as usize;
- assert_eq!(z, y % 256);
-
- // Pointer string formatting! We can't check the output as it changes when libstd changes,
- // but we can make sure Miri does not error.
- format!("{:?}", &mut 13 as *mut _);
-
- // Check that intptrcast is triggered for explicit casts and that it is consistent with
- // transmuting.
- let a: *const i32 = &42;
- let b = transmute_ptr_to_int(a) as u8;
- let c = a as usize as u8;
- assert_eq!(b, c);
-}
+++ /dev/null
-//ignore-windows: Uses POSIX APIs
-//compile-flags: -Zmiri-seed=
-
-#![feature(rustc_private)]
-
-use core::{slice, ptr};
-
-extern crate libc;
-
-fn main() {
- // Test that small allocations sometimes *are* not very aligned.
- let saw_unaligned = (0..64).any(|_| unsafe {
- let p = libc::malloc(3);
- libc::free(p);
- (p as usize) % 4 != 0 // find any that this is *not* 4-aligned
- });
- assert!(saw_unaligned);
-
- unsafe {
- // Use calloc for initialized memory
- let p1 = libc::calloc(20, 1);
-
- // old size < new size
- let p2 = libc::realloc(p1, 40);
- let slice = slice::from_raw_parts(p2 as *const u8, 20);
- assert_eq!(&slice, &[0_u8; 20]);
-
- // old size == new size
- let p3 = libc::realloc(p2, 40);
- let slice = slice::from_raw_parts(p3 as *const u8, 20);
- assert_eq!(&slice, &[0_u8; 20]);
-
- // old size > new size
- let p4 = libc::realloc(p3, 10);
- let slice = slice::from_raw_parts(p4 as *const u8, 10);
- assert_eq!(&slice, &[0_u8; 10]);
-
- libc::free(p4);
- }
-
- unsafe {
- let p1 = libc::malloc(20);
-
- let p2 = libc::realloc(p1, 0);
- assert!(p2.is_null());
- }
-
- unsafe {
- let p1 = libc::realloc(ptr::null_mut(), 20);
- assert!(!p1.is_null());
-
- libc::free(p1);
- }
-}
--- /dev/null
+use std::collections::{self, HashMap};
+use std::hash::{BuildHasherDefault, BuildHasher};
+
+fn test_map<S: BuildHasher>(mut map: HashMap<i32, i32, S>) {
+ map.insert(0, 0);
+ assert_eq!(map.values().fold(0, |x, y| x+y), 0);
+
+ let num = 25;
+ for i in 1..num {
+ map.insert(i, i);
+ }
+ assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2); // check the right things are in the table now
+
+ // Inserting again replaces the existing entries
+ for i in 0..num {
+ map.insert(i, num-1-i);
+ }
+ assert_eq!(map.values().fold(0, |x, y| x+y), num*(num-1)/2);
+
+ // TODO: Test Entry API, Iterators, ...
+
+}
+
+fn main() {
+ if cfg!(target_os = "macos") { // TODO: Implement libstd HashMap seeding for macOS (https://github.com/rust-lang/miri/issues/686).
+ // Until then, use a deterministic map.
+ test_map::<BuildHasherDefault<collections::hash_map::DefaultHasher>>(HashMap::default());
+ } else {
+ test_map(HashMap::new());
+ }
+}
--- /dev/null
+#![feature(allocator_api)]
+
+use std::ptr::NonNull;
+use std::alloc::{Global, Alloc, Layout, System};
+use std::slice;
+
+fn check_alloc<T: Alloc>(mut allocator: T) { unsafe {
+ for &align in &[4, 8, 16, 32] {
+ let layout = Layout::from_size_align(20, align).unwrap();
+
+ for _ in 0..32 {
+ let a = allocator.alloc(layout).unwrap();
+ assert_eq!(a.as_ptr() as usize % align, 0, "pointer is incorrectly aligned");
+ allocator.dealloc(a, layout);
+ }
+
+ let p1 = allocator.alloc_zeroed(layout).unwrap();
+ assert_eq!(p1.as_ptr() as usize % align, 0, "pointer is incorrectly aligned");
+
+ let p2 = allocator.realloc(p1, layout, 40).unwrap();
+ let layout = Layout::from_size_align(40, align).unwrap();
+ assert_eq!(p2.as_ptr() as usize % align, 0, "pointer is incorrectly aligned");
+ let slice = slice::from_raw_parts(p2.as_ptr(), 20);
+ assert_eq!(&slice, &[0_u8; 20]);
+
+ // old size == new size
+ let p3 = allocator.realloc(p2, layout, 40).unwrap();
+ assert_eq!(p3.as_ptr() as usize % align, 0, "pointer is incorrectly aligned");
+ let slice = slice::from_raw_parts(p3.as_ptr(), 20);
+ assert_eq!(&slice, &[0_u8; 20]);
+
+ // old size > new size
+ let p4 = allocator.realloc(p3, layout, 10).unwrap();
+ let layout = Layout::from_size_align(10, align).unwrap();
+ assert_eq!(p4.as_ptr() as usize % align, 0, "pointer is incorrectly aligned");
+ let slice = slice::from_raw_parts(p4.as_ptr(), 10);
+ assert_eq!(&slice, &[0_u8; 10]);
+
+ allocator.dealloc(p4, layout);
+ }
+} }
+
+fn check_align_requests<T: Alloc>(mut allocator: T) {
+ for &size in &[2, 8, 64] { // size less than and bigger than alignment
+ for &align in &[4, 8, 16, 32] { // Be sure to cover less than and bigger than `MIN_ALIGN` for all architectures
+ let iterations = 32;
+ unsafe {
+ let pointers: Vec<_> = (0..iterations).map(|_| {
+ allocator.alloc(Layout::from_size_align(size, align).unwrap()).unwrap()
+ }).collect();
+ for &ptr in &pointers {
+ assert_eq!((ptr.as_ptr() as usize) % align, 0,
+ "Got a pointer less aligned than requested")
+ }
+
+ // Clean up.
+ for &ptr in &pointers {
+ allocator.dealloc(ptr, Layout::from_size_align(size, align).unwrap())
+ }
+ }
+ }
+ }
+}
+
+fn global_to_box() {
+ type T = [i32; 4];
+ let l = Layout::new::<T>();
+ // allocate manually with global allocator, then turn into Box and free there
+ unsafe {
+ let ptr = Global.alloc(l).unwrap().as_ptr() as *mut T;
+ let b = Box::from_raw(ptr);
+ drop(b);
+ }
+}
+
+fn box_to_global() {
+ type T = [i32; 4];
+ let l = Layout::new::<T>();
+ // allocate with the Box, then deallocate manually with global allocator
+ unsafe {
+ let b = Box::new(T::default());
+ let ptr = Box::into_raw(b);
+ Global.dealloc(NonNull::new(ptr as *mut u8).unwrap(), l);
+ }
+}
+
+fn main() {
+ check_alloc(System);
+ check_alloc(Global);
+ check_align_requests(System);
+ check_align_requests(Global);
+ global_to_box();
+ box_to_global();
+}
--- /dev/null
+// This returns a miri pointer at type usize, if the argument is a proper pointer
+fn transmute_ptr_to_int<T>(x: *const T) -> usize {
+ unsafe { std::mem::transmute(x) }
+}
+
+fn main() {
+ // Some casting-to-int with arithmetic.
+ let x = &42 as *const i32 as usize;
+ let y = x * 2;
+ assert_eq!(y, x + x);
+ let z = y as u8 as usize;
+ assert_eq!(z, y % 256);
+
+ // Pointer string formatting! We can't check the output as it changes when libstd changes,
+ // but we can make sure Miri does not error.
+ format!("{:?}", &mut 13 as *mut _);
+
+ // Check that intptrcast is triggered for explicit casts and that it is consistent with
+ // transmuting.
+ let a: *const i32 = &42;
+ let b = transmute_ptr_to_int(a) as u8;
+ let c = a as usize as u8;
+ assert_eq!(b, c);
+}
--- /dev/null
+//ignore-windows: Uses POSIX APIs
+
+#![feature(rustc_private)]
+
+use core::{slice, ptr};
+
+extern crate libc;
+
+fn main() {
+ // Test that small allocations sometimes *are* not very aligned.
+ let saw_unaligned = (0..64).any(|_| unsafe {
+ let p = libc::malloc(3);
+ libc::free(p);
+ (p as usize) % 4 != 0 // find any that this is *not* 4-aligned
+ });
+ assert!(saw_unaligned);
+
+ unsafe {
+ // Use calloc for initialized memory
+ let p1 = libc::calloc(20, 1);
+
+ // old size < new size
+ let p2 = libc::realloc(p1, 40);
+ let slice = slice::from_raw_parts(p2 as *const u8, 20);
+ assert_eq!(&slice, &[0_u8; 20]);
+
+ // old size == new size
+ let p3 = libc::realloc(p2, 40);
+ let slice = slice::from_raw_parts(p3 as *const u8, 20);
+ assert_eq!(&slice, &[0_u8; 20]);
+
+ // old size > new size
+ let p4 = libc::realloc(p3, 10);
+ let slice = slice::from_raw_parts(p4 as *const u8, 10);
+ assert_eq!(&slice, &[0_u8; 10]);
+
+ libc::free(p4);
+ }
+
+ unsafe {
+ let p1 = libc::malloc(20);
+
+ let p2 = libc::realloc(p1, 0);
+ assert!(p2.is_null());
+ }
+
+ unsafe {
+ let p1 = libc::realloc(ptr::null_mut(), 20);
+ assert!(!p1.is_null());
+
+ libc::free(p1);
+ }
+}