File tree Expand file tree Collapse file tree 2 files changed +16
-5
lines changed
compiler/rustc_middle/src/mir/interpret/allocation
src/tools/miri/tests/native-lib/pass Expand file tree Collapse file tree 2 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -196,15 +196,26 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
196
196
Ok ( ( ) )
197
197
}
198
198
199
- pub fn write_wildcards ( & mut self , _alloc_size : usize , _cx : & impl HasDataLayout ) {
199
+ pub fn write_wildcards ( & mut self , alloc_size : usize , cx : & impl HasDataLayout ) {
200
200
// We can only write wildcards in Miri.
201
201
assert ! (
202
202
Prov :: OFFSET_IS_ADDR ,
203
203
"writing wildcard provenance is not supported when `OFFSET_IS_ADDR` is false"
204
204
) ;
205
- let _wildcard = Prov :: WILDCARD . unwrap ( ) ;
205
+ let wildcard = Prov :: WILDCARD . unwrap ( ) ;
206
+ let ptr_size = cx. data_layout ( ) . pointer_size ;
206
207
207
- // TODO: Write wildcards into `self` in intervals of `cx.data_layout().pointer_size` + remaining bytes?
208
+ // Write wildcards in intervals of pointer size.
209
+ let end = Size :: from_bytes ( alloc_size / ptr_size. bytes_usize ( ) ) ;
210
+ for offset in Size :: ZERO ..end {
211
+ self . ptrs . insert ( offset, wildcard) ;
212
+ }
213
+ // Write wildcards into the remaining bytes.
214
+ let last = Size :: from_bytes ( alloc_size) ;
215
+ let bytes = self . bytes . get_or_insert_with ( Box :: default) ;
216
+ for offset in end..last {
217
+ bytes. insert ( offset, wildcard) ;
218
+ } // TODO: Is the above even remotely correct?
208
219
}
209
220
}
210
221
Original file line number Diff line number Diff line change @@ -88,8 +88,8 @@ fn test_dangling() {
88
88
fn write_nullptr ( pptr : * mut * const i32 ) ;
89
89
}
90
90
91
- let x = Box :: new ( 71 ) ;
92
- let mut ptr = x. into_raw ( ) ;
91
+ let x = vec ! [ 71 ] ;
92
+ let mut ptr = x. as_ptr ( ) ;
93
93
drop ( x) ;
94
94
unsafe { write_nullptr ( & mut ptr) } ;
95
95
assert_eq ! ( ptr, std:: ptr:: null( ) ) ;
You can’t perform that action at this time.
0 commit comments