@@ -161,22 +161,14 @@ impl<'mir: 'ecx, 'tcx: 'mir, 'ecx> EvalContextPrivExt<'mir, 'tcx, 'ecx>
161161{
162162}
163163trait EvalContextPrivExt < ' mir : ' ecx , ' tcx : ' mir , ' ecx > : crate :: MiriInterpCxExt < ' mir , ' tcx > {
164- /// Returns the `AllocId` the reborrow was done in, if there is some actual
165- /// memory associated with this pointer. Returns `None` if there is no actual
166- /// memory allocated. Also checks that the reborrow of size `ptr_size` is
167- /// within bounds of the allocation.
168- ///
169- /// Also returns the tag that the pointer should get, which is essentially
170- /// `if new_perm.is_some() { new_tag } else { parent_tag }` along with
171- /// some logging (always) and fake reads (if `new_perm` is
172- /// `Some(NewPermission { perform_read_access: true }`).
164+ /// Returns the provenance that should be used henceforth.
173165 fn tb_reborrow (
174166 & mut self ,
175167 place : & MPlaceTy < ' tcx , Provenance > , // parent tag extracted from here
176168 ptr_size : Size ,
177169 new_perm : NewPermission ,
178170 new_tag : BorTag ,
179- ) -> InterpResult < ' tcx , Option < ( AllocId , BorTag ) > > {
171+ ) -> InterpResult < ' tcx , Option < Provenance > > {
180172 let this = self . eval_context_mut ( ) ;
181173 // Ensure we bail out if the pointer goes out-of-bounds (see miri#1050).
182174 this. check_ptr_access_align (
@@ -222,13 +214,14 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
222214 place. layout. ty,
223215 ) ;
224216 log_creation ( this, None ) ?;
225- return Ok ( None ) ;
217+ // Keep original provenance.
218+ return Ok ( place. ptr . provenance ) ;
226219 }
227220 } ;
228221 log_creation ( this, Some ( ( alloc_id, base_offset, parent_prov) ) ) ?;
229222
230223 let orig_tag = match parent_prov {
231- ProvenanceExtra :: Wildcard => return Ok ( None ) , // TODO: handle wildcard pointers
224+ ProvenanceExtra :: Wildcard => return Ok ( place . ptr . provenance ) , // TODO: handle wildcard pointers
232225 ProvenanceExtra :: Concrete ( tag) => tag,
233226 } ;
234227
@@ -279,7 +272,7 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
279272
280273 // Record the parent-child pair in the tree.
281274 tree_borrows. new_child ( orig_tag, new_tag, new_perm. initial_state , range, span) ?;
282- Ok ( Some ( ( alloc_id, new_tag) ) )
275+ Ok ( Some ( Provenance :: Concrete { alloc_id, tag : new_tag } ) )
283276 }
284277
285278 /// Retags an individual pointer, returning the retagged version.
@@ -315,25 +308,10 @@ trait EvalContextPrivExt<'mir: 'ecx, 'tcx: 'mir, 'ecx>: crate::MiriInterpCxExt<'
315308 let new_tag = this. machine . borrow_tracker . as_mut ( ) . unwrap ( ) . get_mut ( ) . new_ptr ( ) ;
316309
317310 // Compute the actual reborrow.
318- let reborrowed = this. tb_reborrow ( & place, reborrow_size, new_perm, new_tag) ?;
311+ let new_prov = this. tb_reborrow ( & place, reborrow_size, new_perm, new_tag) ?;
319312
320313 // Adjust pointer.
321- let new_place = place. map_provenance ( |p| {
322- p. map ( |prov| {
323- match reborrowed {
324- Some ( ( alloc_id, actual_tag) ) => {
325- // If `reborrow` could figure out the AllocId of this ptr, hard-code it into the new one.
326- // Even if we started out with a wildcard, this newly retagged pointer is tied to that allocation.
327- Provenance :: Concrete { alloc_id, tag : actual_tag }
328- }
329- None => {
330- // Looks like this has to stay a wildcard pointer.
331- assert ! ( matches!( prov, Provenance :: Wildcard ) ) ;
332- Provenance :: Wildcard
333- }
334- }
335- } )
336- } ) ;
314+ let new_place = place. map_provenance ( |_| new_prov) ;
337315
338316 // Return new pointer.
339317 Ok ( ImmTy :: from_immediate ( new_place. to_ref ( this) , val. layout ) )
0 commit comments