2019-07-04 17:06:41 -05:00
|
|
|
// FIXME move this to run-pass, it should work with intptrcast.
|
|
|
|
|
2018-12-26 09:23:04 -06:00
|
|
|
fn f() -> i32 { 42 }
|
|
|
|
|
2017-06-04 20:18:37 -05:00
|
|
|
fn main() {
|
|
|
|
let v = [1i16, 2];
|
2019-04-15 10:06:42 -05:00
|
|
|
let x = &v as *const [i16; 2] as *const i16;
|
2017-06-04 20:18:37 -05:00
|
|
|
let x = unsafe { x.offset(1) };
|
|
|
|
assert_eq!(unsafe { *x }, 2);
|
2018-12-26 09:23:04 -06:00
|
|
|
|
|
|
|
// fn ptr offset
|
|
|
|
unsafe {
|
|
|
|
let p = f as fn() -> i32 as usize;
|
|
|
|
let x = (p as *mut u32).offset(0) as usize;
|
|
|
|
let f: fn() -> i32 = std::mem::transmute(x);
|
|
|
|
assert_eq!(f(), 42);
|
|
|
|
}
|
2017-06-04 20:18:37 -05:00
|
|
|
}
|