Handle size_of_val for slice types.
This commit is contained in:
parent
6d9a748858
commit
b9c37124be
4 changed files with 26 additions and 10 deletions
|
@ -580,7 +580,17 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
|
||||||
let size = self.type_size(ty) as u64;
|
let size = self.type_size(ty) as u64;
|
||||||
self.memory.write_uint(dest, size, dest_size)?;
|
self.memory.write_uint(dest, size, dest_size)?;
|
||||||
} else {
|
} else {
|
||||||
panic!("unimplemented: size_of_val::<{:?}>", ty);
|
match ty.sty {
|
||||||
|
ty::TySlice(_) | ty::TyStr => {
|
||||||
|
let elem_ty = ty.sequence_element_type(self.tcx);
|
||||||
|
let elem_size = self.type_size(elem_ty) as u64;
|
||||||
|
let ptr_size = self.memory.pointer_size as isize;
|
||||||
|
let n = self.memory.read_usize(args[0].offset(ptr_size))?;
|
||||||
|
self.memory.write_uint(dest, n * elem_size, dest_size)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ => panic!("unimplemented: size_of_val::<{:?}>", ty),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ fn slice_index() -> u8 {
|
||||||
|
|
||||||
#[miri_run]
|
#[miri_run]
|
||||||
fn main() {
|
fn main() {
|
||||||
//assert_eq!(empty_array(), []);
|
// assert_eq!(empty_array(), []);
|
||||||
assert_eq!(index_unsafe(), 20);
|
assert_eq!(index_unsafe(), 20);
|
||||||
assert_eq!(index(), 20);
|
assert_eq!(index(), 20);
|
||||||
assert_eq!(slice_index(), 106);
|
assert_eq!(slice_index(), 106);
|
||||||
|
|
|
@ -33,17 +33,10 @@ fn cross_crate_fn_call() -> i64 {
|
||||||
if 1i32.is_positive() { 1 } else { 0 }
|
if 1i32.is_positive() { 1 } else { 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test one of the simplest intrinsics.
|
|
||||||
#[miri_run]
|
|
||||||
fn test_size_of() -> usize {
|
|
||||||
::std::mem::size_of::<Option<i32>>()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[miri_run]
|
#[miri_run]
|
||||||
fn main() {
|
fn main() {
|
||||||
assert_eq!(call(), 2);
|
assert_eq!(call(), 2);
|
||||||
assert_eq!(factorial_recursive(), 3628800);
|
assert_eq!(factorial_recursive(), 3628800);
|
||||||
//assert_eq!(call_generic(), (42, true));
|
assert_eq!(call_generic(), (42, true));
|
||||||
assert_eq!(cross_crate_fn_call(), 1);
|
assert_eq!(cross_crate_fn_call(), 1);
|
||||||
//assert_eq!(test_size_of(), 8);
|
|
||||||
}
|
}
|
||||||
|
|
13
tests/run-pass/intrinsics.rs
Executable file
13
tests/run-pass/intrinsics.rs
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#![feature(custom_attribute)]
|
||||||
|
#![allow(dead_code, unused_attributes)]
|
||||||
|
|
||||||
|
use std::mem::{size_of, size_of_val};
|
||||||
|
|
||||||
|
#[miri_run]
|
||||||
|
fn main() {
|
||||||
|
assert_eq!(size_of::<Option<i32>>(), 8);
|
||||||
|
assert_eq!(size_of_val(&()), 0);
|
||||||
|
assert_eq!(size_of_val(&42), 4);
|
||||||
|
assert_eq!(size_of_val(&[] as &[i32]), 0);
|
||||||
|
assert_eq!(size_of_val(&[1, 2, 3] as &[i32]), 12);
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue