review or fix remaining miri failures in libcore

This commit is contained in:
Ralf Jung 2019-02-09 16:19:21 +01:00
parent 7f5dc49214
commit 72be9a607b
8 changed files with 28 additions and 9 deletions

View File

@ -1,4 +1,4 @@
#![cfg(not(miri))]
#![cfg(not(miri))] // FIXME: A bug in Miri breaks padding in string formatting
mod builders;
mod float;

View File

@ -1,5 +1,3 @@
#![cfg(not(miri))]
mod sip;
use std::hash::{Hash, Hasher};
@ -75,9 +73,11 @@ fn hash<T: Hash>(t: &T) -> u64 {
let cs: &mut [u8] = &mut [1, 2, 3];
let ptr = cs.as_ptr();
let slice_ptr = cs as *const [u8];
#[cfg(not(miri))] // Miri cannot hash pointers
assert_eq!(hash(&slice_ptr), hash(&ptr) + cs.len() as u64);
let slice_ptr = cs as *mut [u8];
#[cfg(not(miri))] // Miri cannot hash pointers
assert_eq!(hash(&slice_ptr), hash(&ptr) + cs.len() as u64);
}

View File

@ -1661,9 +1661,7 @@ fn test_range_step() {
assert_eq!((1..21).rev().step_by(5).collect::<Vec<isize>>(), [20, 15, 10, 5]);
assert_eq!((1..21).rev().step_by(6).collect::<Vec<isize>>(), [20, 14, 8, 2]);
assert_eq!((200..255).step_by(50).collect::<Vec<u8>>(), [200, 250]);
#[cfg(not(miri))] // Miri cannot compare empty slices
assert_eq!((200..-5).step_by(1).collect::<Vec<isize>>(), []);
#[cfg(not(miri))] // Miri cannot compare empty slices
assert_eq!((200..200).step_by(1).collect::<Vec<isize>>(), []);
assert_eq!((0..20).step_by(1).size_hint(), (20, Some(20)));

View File

@ -3,6 +3,7 @@
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_from_u64_overflow() {
Big::from_u64(0x1000000);
}
@ -19,12 +20,14 @@ fn test_add() {
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_add_overflow_1() {
Big::from_small(1).add(&Big::from_u64(0xffffff));
}
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_add_overflow_2() {
Big::from_u64(0xffffff).add(&Big::from_small(1));
}
@ -42,6 +45,7 @@ fn test_add_small() {
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_add_small_overflow() {
Big::from_u64(0xffffff).add_small(1);
}
@ -57,12 +61,14 @@ fn test_sub() {
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_sub_underflow_1() {
Big::from_u64(0x10665).sub(&Big::from_u64(0x10666));
}
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_sub_underflow_2() {
Big::from_small(0).sub(&Big::from_u64(0x123456));
}
@ -76,6 +82,7 @@ fn test_mul_small() {
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_mul_small_overflow() {
Big::from_u64(0x800000).mul_small(2);
}
@ -94,12 +101,14 @@ fn test_mul_pow2() {
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_mul_pow2_overflow_1() {
Big::from_u64(0x1).mul_pow2(24);
}
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_mul_pow2_overflow_2() {
Big::from_u64(0x123).mul_pow2(16);
}
@ -118,12 +127,14 @@ fn test_mul_pow5() {
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_mul_pow5_overflow_1() {
Big::from_small(1).mul_pow5(12);
}
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_mul_pow5_overflow_2() {
Big::from_small(230).mul_pow5(8);
}
@ -141,12 +152,14 @@ fn test_mul_digits() {
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_mul_digits_overflow_1() {
Big::from_u64(0x800000).mul_digits(&[2]);
}
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_mul_digits_overflow_2() {
Big::from_u64(0x1000).mul_digits(&[0, 0x10]);
}
@ -206,6 +219,7 @@ fn test_get_bit() {
#[test]
#[should_panic]
#[cfg(not(miri))] // Miri does not support panics
fn test_get_bit_out_of_range() {
Big::from_small(42).get_bit(24);
}

View File

@ -52,6 +52,7 @@ fn large() {
}
#[test]
#[cfg(not(miri))] // Miri is too slow
fn subnormals() {
test_literal!(5e-324);
test_literal!(91e-324);
@ -63,6 +64,7 @@ fn subnormals() {
}
#[test]
#[cfg(not(miri))] // Miri is too slow
fn infinity() {
test_literal!(1e400);
test_literal!(1e309);

View File

@ -1,3 +1,5 @@
#![cfg(not(miri))] // Miri does not implement ldexp, which most tests here need
use std::prelude::v1::*;
use std::{str, i16, f32, f64, fmt};

View File

@ -1,5 +1,3 @@
#![cfg(not(miri))]
use core::convert::{TryFrom, TryInto};
use core::cmp::PartialEq;
use core::fmt::Debug;

View File

@ -1,5 +1,3 @@
#![cfg(not(miri))]
use core::ptr::*;
use core::cell::RefCell;
@ -42,6 +40,7 @@ struct Pair {
}
#[test]
#[cfg(not(miri))] // This test performs invalid OOB pointer arithmetic
fn test_is_null() {
let p: *const isize = null();
assert!(p.is_null());
@ -147,6 +146,7 @@ fn test_as_ref() {
}
#[test]
#[cfg(not(miri))] // This test is UB according to Stacked Borrows
fn test_as_mut() {
unsafe {
let p: *mut isize = null_mut();
@ -208,6 +208,7 @@ fn test_ptr_addition() {
}
#[test]
#[cfg(not(miri))] // This test performs invalid OOB pointer arithmetic
fn test_ptr_subtraction() {
unsafe {
let xs = vec![0,1,2,3,4,5,6,7,8,9];
@ -251,6 +252,7 @@ fn test_unsized_nonnull() {
#[test]
#[allow(warnings)]
#[cfg(not(miri))] // Miri cannot hash pointers
// Have a symbol for the test below. It doesnt need to be an actual variadic function, match the
// ABI, or even point to an actual executable code, because the function itself is never invoked.
#[no_mangle]
@ -290,6 +292,7 @@ fn drop(&mut self) {
}
#[test]
#[cfg(not(miri))] // Miri cannot compute actual alignment of an allocation
fn align_offset_zst() {
// For pointers of stride = 0, the pointer is already aligned or it cannot be aligned at
// all, because no amount of elements will align the pointer.
@ -304,6 +307,7 @@ fn align_offset_zst() {
}
#[test]
#[cfg(not(miri))] // Miri cannot compute actual alignment of an allocation
fn align_offset_stride1() {
// For pointers of stride = 1, the pointer can always be aligned. The offset is equal to
// number of bytes.
@ -320,6 +324,7 @@ fn align_offset_stride1() {
}
#[test]
#[cfg(not(miri))] // Miri is too slow
fn align_offset_weird_strides() {
#[repr(packed)]
struct A3(u16, u8);