Skip to content

Commit 58e6530

Browse files
committed
Auto merge of #803 - christianpoveda:intptrcast-explicit-casts, r=RalfJung
Add tests for Intptrcast when doing explicit casts r? @RalfJung
2 parents 3525943 + 802dcb7 commit 58e6530

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
7e08576e4276a97b523c25bfd196d419c39c7b87
1+
088b987307b91612ab164026e1dcdd0129fdb62b

tests/run-pass-noseed/intptrcast.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
// compile-flags: -Zmiri-seed=0000000000000000
22

3+
// This returns a miri pointer at type usize, if the argument is a proper pointer
4+
fn transmute_ptr_to_int<T>(x: *const T) -> usize {
5+
unsafe { std::mem::transmute(x) }
6+
}
7+
38
fn main() {
49
// Some casting-to-int with arithmetic.
5-
let x = &42 as *const i32 as usize;
10+
let x = &42 as *const i32 as usize;
611
let y = x * 2;
712
assert_eq!(y, x + x);
813
let z = y as u8 as usize;
@@ -11,4 +16,11 @@ fn main() {
1116
// Pointer string formatting! We can't check the output as it changes when libstd changes,
1217
// but we can make sure Miri does not error.
1318
format!("{:?}", &mut 13 as *mut _);
19+
20+
// Check that intptrcast is triggered for explicit casts and that it is consistent with
21+
// transmuting.
22+
let a: *const i32 = &42;
23+
let b = transmute_ptr_to_int(a) as u8;
24+
let c = a as usize as u8;
25+
assert_eq!(b, c);
1426
}

tests/run-pass-noseed/ptr_int_casts.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// FIXME move this to run-pass, it should work with intptrcast.
12
use std::mem;
23
use std::ptr;
34

tests/run-pass/ptr_offset.rs renamed to tests/run-pass-noseed/ptr_offset.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// FIXME move this to run-pass, it should work with intptrcast.
2+
13
fn f() -> i32 { 42 }
24

35
fn main() {

0 commit comments

Comments
 (0)