File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -122,10 +122,18 @@ impl<'mir, 'tcx> GlobalStateInner {
122
122
123
123
// Special-case NULL, it is always an invalid pointer.
124
124
if addr == 0 || global_state. provenance_mode == ProvenanceMode :: Strict {
125
- return Pointer :: new ( None , Size :: from_bytes ( addr) ) ;
125
+ Pointer :: new ( None , Size :: from_bytes ( addr) )
126
+ } else if global_state. provenance_mode == ProvenanceMode :: Legacy {
127
+ let alloc_id = Self :: alloc_id_from_addr ( ecx, addr) ;
128
+
129
+ Pointer :: new (
130
+ alloc_id
131
+ . map ( |alloc_id| Tag :: Concrete ( ConcreteTag { alloc_id, sb : SbTag :: Untagged } ) ) ,
132
+ Size :: from_bytes ( addr) ,
133
+ )
134
+ } else {
135
+ Pointer :: new ( Some ( Tag :: Wildcard ) , Size :: from_bytes ( addr) )
126
136
}
127
-
128
- Pointer :: new ( Some ( Tag :: Wildcard ) , Size :: from_bytes ( addr) )
129
137
}
130
138
131
139
fn alloc_base_addr ( ecx : & MiriEvalContext < ' mir , ' tcx > , alloc_id : AllocId ) -> u64 {
Original file line number Diff line number Diff line change
1
+ // compile-flags: -Zmiri-disable-stacked-borrows
2
+ #![ feature( strict_provenance) ]
3
+
4
+ use std:: ptr;
5
+
6
+ // Make sure that with legacy provenance, the allocation id of
7
+ // a casted pointer is determined at cast-time
8
+ fn main ( ) {
9
+ let x: i32 = 0 ;
10
+ let y: i32 = 1 ;
11
+
12
+ let x_ptr = & x as * const i32 ;
13
+ let y_ptr = & y as * const i32 ;
14
+
15
+ let x_usize = x_ptr. expose_addr ( ) ;
16
+ let y_usize = y_ptr. expose_addr ( ) ;
17
+
18
+ let ptr = ptr:: from_exposed_addr :: < i32 > ( y_usize) ;
19
+ let ptr = ptr. with_addr ( x_usize) ;
20
+ assert_eq ! ( unsafe { * ptr } , 0 ) ; //~ ERROR pointer to 4 bytes starting at offset -20 is out-of-bounds
21
+ }
You can’t perform that action at this time.
0 commit comments