fix arith_offset not taking the size of the type into account; test for offset
This commit is contained in:
parent
1d0e622a81
commit
70227c87bf
@ -43,10 +43,11 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
||||
|
||||
|
||||
"arith_offset" => {
|
||||
// FIXME: Switch to non-checked, wrapped version of pointer_offset
|
||||
let offset = self.value_to_primval(arg_vals[1], isize)?.to_i128()? as i64;
|
||||
let ptr = arg_vals[0].read_ptr(&self.memory)?;
|
||||
let offset = self.value_to_primval(arg_vals[1], isize)?.to_i128()?;
|
||||
let new_ptr = ptr.signed_offset(offset as i64);
|
||||
self.write_primval(dest, PrimVal::Ptr(new_ptr), dest_ty)?;
|
||||
let result_ptr = self.pointer_offset(ptr, substs.type_at(0), offset)?;
|
||||
self.write_primval(dest, PrimVal::Ptr(result_ptr), dest_ty)?;
|
||||
}
|
||||
|
||||
"assume" => {
|
||||
|
6
tests/run-pass/ptr_arith_offset.rs
Normal file
6
tests/run-pass/ptr_arith_offset.rs
Normal file
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
let v = [1i16, 2];
|
||||
let x = &v as *const i16;
|
||||
let x = x.wrapping_offset(1);
|
||||
assert_eq!(unsafe { *x }, 2);
|
||||
}
|
6
tests/run-pass/ptr_offset.rs
Normal file
6
tests/run-pass/ptr_offset.rs
Normal file
@ -0,0 +1,6 @@
|
||||
fn main() {
|
||||
let v = [1i16, 2];
|
||||
let x = &v as *const i16;
|
||||
let x = unsafe { x.offset(1) };
|
||||
assert_eq!(unsafe { *x }, 2);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user