fix (un)likely intrinsics

This commit is contained in:
Ralf Jung 2019-02-09 13:07:55 +01:00
parent c4c12ade33
commit 0f6e82db36
4 changed files with 47 additions and 25 deletions

View file

@ -245,7 +245,13 @@ pub trait EvalContextExt<'a, 'mir, 'tcx: 'a+'mir>: crate::MiriEvalContextExt<'a,
this.binop_ignore_overflow(mir::BinOp::Div, a, b, dest)?;
},
"likely" | "unlikely" | "forget" => {}
"forget" => {}
"likely" | "unlikely" => {
// These just return their argument
let b = this.read_immediate(args[0])?;
this.write_immediate(*b, dest)?;
}
"init" => {
// Check fast path: we don't want to force an allocation in case the destination is a simple value,

40
tests/run-pass/iter.rs Normal file
View file

@ -0,0 +1,40 @@
fn iter_empty_and_zst() {
for _ in Vec::<u32>::new().iter() { // this iterates over a Unique::empty()
panic!("We should never be here.");
}
// Iterate over a ZST (uses arith_offset internally)
let mut count = 0;
for _ in &[(), (), ()] {
count += 1;
}
assert_eq!(count, 3);
}
fn test_iterator_step_by_nth() {
let mut it = (0..16).step_by(5);
assert_eq!(it.nth(0), Some(0));
assert_eq!(it.nth(0), Some(5));
assert_eq!(it.nth(0), Some(10));
assert_eq!(it.nth(0), Some(15));
assert_eq!(it.nth(0), None);
}
fn iter_any() {
let f = |x: &u8| { 10u8 == *x };
f(&1u8);
let g = |(), x: &u8| { 10u8 == *x };
g((), &1u8);
let h = |(), (), x: &u8| { 10u8 == *x };
h((), (), &1u8);
[1, 2, 3u8].into_iter().any(|elt| 10 == *elt);
}
fn main() {
test_iterator_step_by_nth();
iter_any();
iter_empty_and_zst();
}

View file

@ -1,12 +0,0 @@
pub fn main() {
let f = |x: &u8| { 10u8 == *x };
f(&1u8);
let g = |(), x: &u8| { 10u8 == *x };
g((), &1u8);
let h = |(), (), x: &u8| { 10u8 == *x };
h((), (), &1u8);
[1, 2, 3u8].into_iter().any(|elt| 10 == *elt);
}

View file

@ -1,12 +0,0 @@
fn main() {
for _ in Vec::<u32>::new().iter() { // this iterates over a Unique::empty()
panic!("We should never be here.");
}
// Iterate over a ZST (uses arith_offset internally)
let mut count = 0;
for _ in &[(), (), ()] {
count += 1;
}
assert_eq!(count, 3);
}