Skip to content

Commit 074e20e

Browse files
committed
Add intptrcast test for explicit casts
1 parent ce5e910 commit 074e20e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tests/run-pass-noseed/intptrcast.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// compile-flags: -Zmiri-seed=0000000000000000
2+
fn transmute_ptr_to_int<T>(x: *const T) -> usize {
3+
unsafe { std::mem::transmute::<*const T, usize>(x) * 1 }
4+
}
25

36
fn main() {
47
// Some casting-to-int with arithmetic.
@@ -11,4 +14,11 @@ fn main() {
1114
// Pointer string formatting! We can't check the output as it changes when libstd changes,
1215
// but we can make sure Miri does not error.
1316
format!("{:?}", &mut 13 as *mut _);
17+
18+
// Check that intptrcast is triggered for explicit casts and that it is consistent with
19+
// transmuting.
20+
let a: *const i32 = &42;
21+
let b = transmute_ptr_to_int(a) as u8;
22+
let c = a as usize as u8;
23+
assert_eq!(b, c);
1424
}

0 commit comments

Comments
 (0)