Skip to content

Commit fea220c

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 ce5e910 + 8dfb278 commit fea220c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-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
}

0 commit comments

Comments
 (0)