@@ -309,14 +309,14 @@ impl<'tcx> Stack {
309
309
310
310
/// Test if a memory `access` using pointer tagged `tag` is granted.
311
311
/// If yes, return the index of the item that granted it.
312
- fn access ( & mut self , access : AccessKind , tag : Tag , global : & GlobalState ) -> InterpResult < ' tcx > {
312
+ fn access ( & mut self , access : AccessKind , ptr : Pointer < Tag > , global : & GlobalState ) -> InterpResult < ' tcx > {
313
313
// Two main steps: Find granting item, remove incompatible items above.
314
314
315
315
// Step 1: Find granting item.
316
- let granting_idx = self . find_granting ( access, tag) . ok_or_else ( || {
316
+ let granting_idx = self . find_granting ( access, ptr . tag ) . ok_or_else ( || {
317
317
err_sb_ub ( format ! (
318
- "no item granting {} to tag {:?} found in borrow stack." ,
319
- access, tag
318
+ "no item granting {} to tag {:?} at {} found in borrow stack." ,
319
+ access, ptr . tag, ptr . erase_tag ( ) ,
320
320
) )
321
321
} ) ?;
322
322
@@ -328,7 +328,7 @@ impl<'tcx> Stack {
328
328
let first_incompatible_idx = self . find_first_write_incompatible ( granting_idx) ;
329
329
for item in self . borrows . drain ( first_incompatible_idx..) . rev ( ) {
330
330
trace ! ( "access: popping item {:?}" , item) ;
331
- Stack :: check_protector ( & item, Some ( tag) , global) ?;
331
+ Stack :: check_protector ( & item, Some ( ptr . tag ) , global) ?;
332
332
}
333
333
} else {
334
334
// On a read, *disable* all `Unique` above the granting item. This ensures U2 for read accesses.
@@ -343,7 +343,7 @@ impl<'tcx> Stack {
343
343
let item = & mut self . borrows [ idx] ;
344
344
if item. perm == Permission :: Unique {
345
345
trace ! ( "access: disabling item {:?}" , item) ;
346
- Stack :: check_protector ( item, Some ( tag) , global) ?;
346
+ Stack :: check_protector ( item, Some ( ptr . tag ) , global) ?;
347
347
item. perm = Permission :: Disabled ;
348
348
}
349
349
}
@@ -355,12 +355,12 @@ impl<'tcx> Stack {
355
355
356
356
/// Deallocate a location: Like a write access, but also there must be no
357
357
/// active protectors at all because we will remove all items.
358
- fn dealloc ( & mut self , tag : Tag , global : & GlobalState ) -> InterpResult < ' tcx > {
358
+ fn dealloc ( & mut self , ptr : Pointer < Tag > , global : & GlobalState ) -> InterpResult < ' tcx > {
359
359
// Step 1: Find granting item.
360
- self . find_granting ( AccessKind :: Write , tag) . ok_or_else ( || {
360
+ self . find_granting ( AccessKind :: Write , ptr . tag ) . ok_or_else ( || {
361
361
err_sb_ub ( format ! (
362
- "no item granting write access for deallocation to tag {:?} found in borrow stack" ,
363
- tag,
362
+ "no item granting write access for deallocation to tag {:?} at {} found in borrow stack" ,
363
+ ptr . tag, ptr . erase_tag ( ) ,
364
364
) )
365
365
} ) ?;
366
366
@@ -372,20 +372,20 @@ impl<'tcx> Stack {
372
372
Ok ( ( ) )
373
373
}
374
374
375
- /// Derived a new pointer from one with the given tag.
375
+ /// Derive a new pointer from one with the given tag.
376
376
/// `weak` controls whether this operation is weak or strong: weak granting does not act as
377
377
/// an access, and they add the new item directly on top of the one it is derived
378
378
/// from instead of all the way at the top of the stack.
379
- fn grant ( & mut self , derived_from : Tag , new : Item , global : & GlobalState ) -> InterpResult < ' tcx > {
379
+ fn grant ( & mut self , derived_from : Pointer < Tag > , new : Item , global : & GlobalState ) -> InterpResult < ' tcx > {
380
380
// Figure out which access `perm` corresponds to.
381
381
let access =
382
382
if new. perm . grants ( AccessKind :: Write ) { AccessKind :: Write } else { AccessKind :: Read } ;
383
383
// Now we figure out which item grants our parent (`derived_from`) this kind of access.
384
384
// We use that to determine where to put the new item.
385
- let granting_idx = self . find_granting ( access, derived_from)
385
+ let granting_idx = self . find_granting ( access, derived_from. tag )
386
386
. ok_or_else ( || err_sb_ub ( format ! (
387
- "trying to reborrow for {:?}, but parent tag {:?} does not have an appropriate item in the borrow stack" ,
388
- new. perm, derived_from,
387
+ "trying to reborrow for {:?} at {} , but parent tag {:?} does not have an appropriate item in the borrow stack" ,
388
+ new. perm, derived_from. erase_tag ( ) , derived_from . tag ,
389
389
) ) ) ?;
390
390
391
391
// Compute where to put the new item.
@@ -443,12 +443,14 @@ impl<'tcx> Stacks {
443
443
& self ,
444
444
ptr : Pointer < Tag > ,
445
445
size : Size ,
446
- f : impl Fn ( & mut Stack , & GlobalState ) -> InterpResult < ' tcx > ,
446
+ f : impl Fn ( Pointer < Tag > , & mut Stack , & GlobalState ) -> InterpResult < ' tcx > ,
447
447
) -> InterpResult < ' tcx > {
448
448
let global = self . global . borrow ( ) ;
449
449
let mut stacks = self . stacks . borrow_mut ( ) ;
450
- for stack in stacks. iter_mut ( ptr. offset , size) {
451
- f ( stack, & * global) ?;
450
+ for ( offset, stack) in stacks. iter_mut ( ptr. offset , size) {
451
+ let mut cur_ptr = ptr;
452
+ cur_ptr. offset = offset;
453
+ f ( cur_ptr, stack, & * global) ?;
452
454
}
453
455
Ok ( ( ) )
454
456
}
@@ -487,19 +489,13 @@ impl Stacks {
487
489
#[ inline( always) ]
488
490
pub fn memory_read < ' tcx > ( & self , ptr : Pointer < Tag > , size : Size ) -> InterpResult < ' tcx > {
489
491
trace ! ( "read access with tag {:?}: {:?}, size {}" , ptr. tag, ptr. erase_tag( ) , size. bytes( ) ) ;
490
- self . for_each ( ptr, size, |stack, global| {
491
- stack. access ( AccessKind :: Read , ptr. tag , global) ?;
492
- Ok ( ( ) )
493
- } )
492
+ self . for_each ( ptr, size, |ptr, stack, global| stack. access ( AccessKind :: Read , ptr, global) )
494
493
}
495
494
496
495
#[ inline( always) ]
497
496
pub fn memory_written < ' tcx > ( & mut self , ptr : Pointer < Tag > , size : Size ) -> InterpResult < ' tcx > {
498
497
trace ! ( "write access with tag {:?}: {:?}, size {}" , ptr. tag, ptr. erase_tag( ) , size. bytes( ) ) ;
499
- self . for_each ( ptr, size, |stack, global| {
500
- stack. access ( AccessKind :: Write , ptr. tag , global) ?;
501
- Ok ( ( ) )
502
- } )
498
+ self . for_each ( ptr, size, |ptr, stack, global| stack. access ( AccessKind :: Write , ptr, global) )
503
499
}
504
500
505
501
#[ inline( always) ]
@@ -509,7 +505,7 @@ impl Stacks {
509
505
size : Size ,
510
506
) -> InterpResult < ' tcx > {
511
507
trace ! ( "deallocation with tag {:?}: {:?}, size {}" , ptr. tag, ptr. erase_tag( ) , size. bytes( ) ) ;
512
- self . for_each ( ptr, size, |stack, global| stack. dealloc ( ptr. tag , global) )
508
+ self . for_each ( ptr, size, |ptr , stack, global| stack. dealloc ( ptr, global) )
513
509
}
514
510
}
515
511
@@ -561,14 +557,14 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
561
557
Permission :: SharedReadWrite
562
558
} ;
563
559
let item = Item { perm, tag : new_tag, protector } ;
564
- stacked_borrows. for_each ( cur_ptr, size, |stack, global| {
565
- stack. grant ( cur_ptr. tag , item, global)
560
+ stacked_borrows. for_each ( cur_ptr, size, |cur_ptr , stack, global| {
561
+ stack. grant ( cur_ptr, item, global)
566
562
} )
567
563
} ) ;
568
564
}
569
565
} ;
570
566
let item = Item { perm, tag : new_tag, protector } ;
571
- stacked_borrows. for_each ( ptr, size, |stack, global| stack. grant ( ptr. tag , item, global) )
567
+ stacked_borrows. for_each ( ptr, size, |ptr , stack, global| stack. grant ( ptr, item, global) )
572
568
}
573
569
574
570
/// Retags an indidual pointer, returning the retagged version.
0 commit comments