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> {
196196 Ok ( ( ) )
197197 }
198198
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 ) {
200200 // We can only write wildcards in Miri.
201201 assert ! (
202202 Prov :: OFFSET_IS_ADDR ,
203203 "writing wildcard provenance is not supported when `OFFSET_IS_ADDR` is false"
204204 ) ;
205- let _wildcard = Prov :: WILDCARD . unwrap ( ) ;
205+ let wildcard = Prov :: WILDCARD . unwrap ( ) ;
206+ let ptr_size = cx. data_layout ( ) . pointer_size ;
206207
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?
208219 }
209220}
210221
Original file line number Diff line number Diff line change @@ -88,8 +88,8 @@ fn test_dangling() {
8888 fn write_nullptr ( pptr : * mut * const i32 ) ;
8989 }
9090
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 ( ) ;
9393 drop ( x) ;
9494 unsafe { write_nullptr ( & mut ptr) } ;
9595 assert_eq ! ( ptr, std:: ptr:: null( ) ) ;
You can’t perform that action at this time.
0 commit comments