Skip to content

Commit 72be9a6

Browse files
committed
review or fix remaining miri failures in libcore
1 parent 7f5dc49 commit 72be9a6

File tree

8 files changed

+28
-9
lines changed

8 files changed

+28
-9
lines changed

src/libcore/tests/fmt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg(not(miri))]
1+
#![cfg(not(miri))] // FIXME: A bug in Miri breaks padding in string formatting
22

33
mod builders;
44
mod float;

src/libcore/tests/hash/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(not(miri))]
2-
31
mod sip;
42

53
use std::hash::{Hash, Hasher};
@@ -75,9 +73,11 @@ fn test_writer_hasher() {
7573
let cs: &mut [u8] = &mut [1, 2, 3];
7674
let ptr = cs.as_ptr();
7775
let slice_ptr = cs as *const [u8];
76+
#[cfg(not(miri))] // Miri cannot hash pointers
7877
assert_eq!(hash(&slice_ptr), hash(&ptr) + cs.len() as u64);
7978

8079
let slice_ptr = cs as *mut [u8];
80+
#[cfg(not(miri))] // Miri cannot hash pointers
8181
assert_eq!(hash(&slice_ptr), hash(&ptr) + cs.len() as u64);
8282
}
8383

src/libcore/tests/iter.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,9 +1661,7 @@ fn test_range_step() {
16611661
assert_eq!((1..21).rev().step_by(5).collect::<Vec<isize>>(), [20, 15, 10, 5]);
16621662
assert_eq!((1..21).rev().step_by(6).collect::<Vec<isize>>(), [20, 14, 8, 2]);
16631663
assert_eq!((200..255).step_by(50).collect::<Vec<u8>>(), [200, 250]);
1664-
#[cfg(not(miri))] // Miri cannot compare empty slices
16651664
assert_eq!((200..-5).step_by(1).collect::<Vec<isize>>(), []);
1666-
#[cfg(not(miri))] // Miri cannot compare empty slices
16671665
assert_eq!((200..200).step_by(1).collect::<Vec<isize>>(), []);
16681666

16691667
assert_eq!((0..20).step_by(1).size_hint(), (20, Some(20)));

src/libcore/tests/num/bignum.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use core::num::bignum::tests::Big8x3 as Big;
33

44
#[test]
55
#[should_panic]
6+
#[cfg(not(miri))] // Miri does not support panics
67
fn test_from_u64_overflow() {
78
Big::from_u64(0x1000000);
89
}
@@ -19,12 +20,14 @@ fn test_add() {
1920

2021
#[test]
2122
#[should_panic]
23+
#[cfg(not(miri))] // Miri does not support panics
2224
fn test_add_overflow_1() {
2325
Big::from_small(1).add(&Big::from_u64(0xffffff));
2426
}
2527

2628
#[test]
2729
#[should_panic]
30+
#[cfg(not(miri))] // Miri does not support panics
2831
fn test_add_overflow_2() {
2932
Big::from_u64(0xffffff).add(&Big::from_small(1));
3033
}
@@ -42,6 +45,7 @@ fn test_add_small() {
4245

4346
#[test]
4447
#[should_panic]
48+
#[cfg(not(miri))] // Miri does not support panics
4549
fn test_add_small_overflow() {
4650
Big::from_u64(0xffffff).add_small(1);
4751
}
@@ -57,12 +61,14 @@ fn test_sub() {
5761

5862
#[test]
5963
#[should_panic]
64+
#[cfg(not(miri))] // Miri does not support panics
6065
fn test_sub_underflow_1() {
6166
Big::from_u64(0x10665).sub(&Big::from_u64(0x10666));
6267
}
6368

6469
#[test]
6570
#[should_panic]
71+
#[cfg(not(miri))] // Miri does not support panics
6672
fn test_sub_underflow_2() {
6773
Big::from_small(0).sub(&Big::from_u64(0x123456));
6874
}
@@ -76,6 +82,7 @@ fn test_mul_small() {
7682

7783
#[test]
7884
#[should_panic]
85+
#[cfg(not(miri))] // Miri does not support panics
7986
fn test_mul_small_overflow() {
8087
Big::from_u64(0x800000).mul_small(2);
8188
}
@@ -94,12 +101,14 @@ fn test_mul_pow2() {
94101

95102
#[test]
96103
#[should_panic]
104+
#[cfg(not(miri))] // Miri does not support panics
97105
fn test_mul_pow2_overflow_1() {
98106
Big::from_u64(0x1).mul_pow2(24);
99107
}
100108

101109
#[test]
102110
#[should_panic]
111+
#[cfg(not(miri))] // Miri does not support panics
103112
fn test_mul_pow2_overflow_2() {
104113
Big::from_u64(0x123).mul_pow2(16);
105114
}
@@ -118,12 +127,14 @@ fn test_mul_pow5() {
118127

119128
#[test]
120129
#[should_panic]
130+
#[cfg(not(miri))] // Miri does not support panics
121131
fn test_mul_pow5_overflow_1() {
122132
Big::from_small(1).mul_pow5(12);
123133
}
124134

125135
#[test]
126136
#[should_panic]
137+
#[cfg(not(miri))] // Miri does not support panics
127138
fn test_mul_pow5_overflow_2() {
128139
Big::from_small(230).mul_pow5(8);
129140
}
@@ -141,12 +152,14 @@ fn test_mul_digits() {
141152

142153
#[test]
143154
#[should_panic]
155+
#[cfg(not(miri))] // Miri does not support panics
144156
fn test_mul_digits_overflow_1() {
145157
Big::from_u64(0x800000).mul_digits(&[2]);
146158
}
147159

148160
#[test]
149161
#[should_panic]
162+
#[cfg(not(miri))] // Miri does not support panics
150163
fn test_mul_digits_overflow_2() {
151164
Big::from_u64(0x1000).mul_digits(&[0, 0x10]);
152165
}
@@ -206,6 +219,7 @@ fn test_get_bit() {
206219

207220
#[test]
208221
#[should_panic]
222+
#[cfg(not(miri))] // Miri does not support panics
209223
fn test_get_bit_out_of_range() {
210224
Big::from_small(42).get_bit(24);
211225
}

src/libcore/tests/num/dec2flt/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fn large() {
5252
}
5353

5454
#[test]
55+
#[cfg(not(miri))] // Miri is too slow
5556
fn subnormals() {
5657
test_literal!(5e-324);
5758
test_literal!(91e-324);
@@ -63,6 +64,7 @@ fn subnormals() {
6364
}
6465

6566
#[test]
67+
#[cfg(not(miri))] // Miri is too slow
6668
fn infinity() {
6769
test_literal!(1e400);
6870
test_literal!(1e309);

src/libcore/tests/num/flt2dec/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(not(miri))] // Miri does not implement ldexp, which most tests here need
2+
13
use std::prelude::v1::*;
24
use std::{str, i16, f32, f64, fmt};
35

src/libcore/tests/num/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(not(miri))]
2-
31
use core::convert::{TryFrom, TryInto};
42
use core::cmp::PartialEq;
53
use core::fmt::Debug;

src/libcore/tests/ptr.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(not(miri))]
2-
31
use core::ptr::*;
42
use core::cell::RefCell;
53

@@ -42,6 +40,7 @@ fn test() {
4240
}
4341

4442
#[test]
43+
#[cfg(not(miri))] // This test performs invalid OOB pointer arithmetic
4544
fn test_is_null() {
4645
let p: *const isize = null();
4746
assert!(p.is_null());
@@ -147,6 +146,7 @@ fn test_as_ref() {
147146
}
148147

149148
#[test]
149+
#[cfg(not(miri))] // This test is UB according to Stacked Borrows
150150
fn test_as_mut() {
151151
unsafe {
152152
let p: *mut isize = null_mut();
@@ -208,6 +208,7 @@ fn test_ptr_addition() {
208208
}
209209

210210
#[test]
211+
#[cfg(not(miri))] // This test performs invalid OOB pointer arithmetic
211212
fn test_ptr_subtraction() {
212213
unsafe {
213214
let xs = vec![0,1,2,3,4,5,6,7,8,9];
@@ -251,6 +252,7 @@ fn test_unsized_nonnull() {
251252

252253
#[test]
253254
#[allow(warnings)]
255+
#[cfg(not(miri))] // Miri cannot hash pointers
254256
// Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the
255257
// ABI, or even point to an actual executable code, because the function itself is never invoked.
256258
#[no_mangle]
@@ -290,6 +292,7 @@ fn write_unaligned_drop() {
290292
}
291293

292294
#[test]
295+
#[cfg(not(miri))] // Miri cannot compute actual alignment of an allocation
293296
fn align_offset_zst() {
294297
// For pointers of stride = 0, the pointer is already aligned or it cannot be aligned at
295298
// all, because no amount of elements will align the pointer.
@@ -304,6 +307,7 @@ fn align_offset_zst() {
304307
}
305308

306309
#[test]
310+
#[cfg(not(miri))] // Miri cannot compute actual alignment of an allocation
307311
fn align_offset_stride1() {
308312
// For pointers of stride = 1, the pointer can always be aligned. The offset is equal to
309313
// number of bytes.
@@ -320,6 +324,7 @@ fn align_offset_stride1() {
320324
}
321325

322326
#[test]
327+
#[cfg(not(miri))] // Miri is too slow
323328
fn align_offset_weird_strides() {
324329
#[repr(packed)]
325330
struct A3(u16, u8);

0 commit comments

Comments
 (0)