Skip to content

Commit

Permalink
Auto merge of #803 - christianpoveda:intptrcast-explicit-casts, r=Ral…
Browse files Browse the repository at this point in the history
…fJung

Add tests for Intptrcast when doing explicit casts

r? @RalfJung
  • Loading branch information
bors committed Jul 4, 2019
2 parents 3525943 + 802dcb7 commit 58e6530
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7e08576e4276a97b523c25bfd196d419c39c7b87
088b987307b91612ab164026e1dcdd0129fdb62b
14 changes: 13 additions & 1 deletion tests/run-pass-noseed/intptrcast.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// compile-flags: -Zmiri-seed=0000000000000000

// This returns a miri pointer at type usize, if the argument is a proper pointer
fn transmute_ptr_to_int<T>(x: *const T) -> usize {
unsafe { std::mem::transmute(x) }
}

fn main() {
// Some casting-to-int with arithmetic.
let x = &42 as *const i32 as usize;
let x = &42 as *const i32 as usize;
let y = x * 2;
assert_eq!(y, x + x);
let z = y as u8 as usize;
Expand All @@ -11,4 +16,11 @@ fn main() {
// Pointer string formatting! We can't check the output as it changes when libstd changes,
// but we can make sure Miri does not error.
format!("{:?}", &mut 13 as *mut _);

// Check that intptrcast is triggered for explicit casts and that it is consistent with
// transmuting.
let a: *const i32 = &42;
let b = transmute_ptr_to_int(a) as u8;
let c = a as usize as u8;
assert_eq!(b, c);
}
1 change: 1 addition & 0 deletions tests/run-pass-noseed/ptr_int_casts.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// FIXME move this to run-pass, it should work with intptrcast.
use std::mem;
use std::ptr;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// FIXME move this to run-pass, it should work with intptrcast.

fn f() -> i32 { 42 }

fn main() {
Expand Down

0 comments on commit 58e6530

Please sign in to comment.