mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-31 21:47:15 +03:00
fix arith_offset not taking the size of the type into account; test for offset
This commit is contained in:
@@ -43,10 +43,11 @@ pub(super) fn call_intrinsic(
|
||||
|
||||
|
||||
"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" => {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user