File tree 2 files changed +14
-2
lines changed
2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 1
- 7e08576e4276a97b523c25bfd196d419c39c7b87
1
+ 088b987307b91612ab164026e1dcdd0129fdb62b
Original file line number Diff line number Diff line change 1
1
// compile-flags: -Zmiri-seed=0000000000000000
2
2
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
+
3
8
fn main ( ) {
4
9
// Some casting-to-int with arithmetic.
5
- let x = & 42 as * const i32 as usize ;
10
+ let x = & 42 as * const i32 as usize ;
6
11
let y = x * 2 ;
7
12
assert_eq ! ( y, x + x) ;
8
13
let z = y as u8 as usize ;
@@ -11,4 +16,11 @@ fn main() {
11
16
// Pointer string formatting! We can't check the output as it changes when libstd changes,
12
17
// but we can make sure Miri does not error.
13
18
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) ;
14
26
}
You can’t perform that action at this time.
0 commit comments