File tree Expand file tree Collapse file tree 4 files changed +17
-2
lines changed Expand file tree Collapse file tree 4 files changed +17
-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 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+
38fn 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}
Original file line number Diff line number Diff line change 1+ // FIXME move this to run-pass, it should work with intptrcast.
12use std:: mem;
23use std:: ptr;
34
Original file line number Diff line number Diff line change 1+ // FIXME move this to run-pass, it should work with intptrcast.
2+
13fn f ( ) -> i32 { 42 }
24
35fn main ( ) {
You can’t perform that action at this time.
0 commit comments