|
2 | 2 | //! `Machine` trait. |
3 | 3 |
|
4 | 4 | use std::borrow::Cow; |
5 | | -use std::cell::{Cell, RefCell}; |
| 5 | +use std::cell::RefCell; |
6 | 6 | use std::collections::hash_map::Entry; |
7 | 7 | use std::fmt; |
8 | 8 | use std::path::Path; |
@@ -336,20 +336,11 @@ pub struct AllocExtra<'tcx> { |
336 | 336 | /// if this allocation is leakable. The backtrace is not |
337 | 337 | /// pruned yet; that should be done before printing it. |
338 | 338 | pub backtrace: Option<Vec<FrameInfo<'tcx>>>, |
339 | | - /// An offset inside this allocation that was deemed aligned even for symbolic alignment checks. |
340 | | - /// Invariant: the promised alignment will never be less than the native alignment of this allocation. |
341 | | - pub symbolic_alignment: Cell<Option<(Size, Align)>>, |
342 | 339 | } |
343 | 340 |
|
344 | 341 | impl VisitProvenance for AllocExtra<'_> { |
345 | 342 | fn visit_provenance(&self, visit: &mut VisitWith<'_>) { |
346 | | - let AllocExtra { |
347 | | - borrow_tracker, |
348 | | - data_race, |
349 | | - weak_memory, |
350 | | - backtrace: _, |
351 | | - symbolic_alignment: _, |
352 | | - } = self; |
| 343 | + let AllocExtra { borrow_tracker, data_race, weak_memory, backtrace: _ } = self; |
353 | 344 |
|
354 | 345 | borrow_tracker.visit_provenance(visit); |
355 | 346 | data_race.visit_provenance(visit); |
@@ -572,6 +563,14 @@ pub struct MiriMachine<'mir, 'tcx> { |
572 | 563 | /// that is fixed per stack frame; this lets us have sometimes different results for the |
573 | 564 | /// same const while ensuring consistent results within a single call. |
574 | 565 | const_cache: RefCell<FxHashMap<(mir::Const<'tcx>, usize), OpTy<'tcx, Provenance>>>, |
| 566 | + |
| 567 | + /// For each allocation, an offset inside that allocation that was deemed aligned even for |
| 568 | + /// symbolic alignment checks. This cannot be stored in `AllocExtra` since it needs to be |
| 569 | + /// tracked for vtables and function allocations as well as regular allocations. |
| 570 | + /// |
| 571 | + /// Invariant: the promised alignment will never be less than the native alignment of the |
| 572 | + /// allocation. |
| 573 | + pub(crate) symbolic_alignment: RefCell<FxHashMap<AllocId, (Size, Align)>>, |
575 | 574 | } |
576 | 575 |
|
577 | 576 | impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> { |
@@ -698,6 +697,7 @@ impl<'mir, 'tcx> MiriMachine<'mir, 'tcx> { |
698 | 697 | collect_leak_backtraces: config.collect_leak_backtraces, |
699 | 698 | allocation_spans: RefCell::new(FxHashMap::default()), |
700 | 699 | const_cache: RefCell::new(FxHashMap::default()), |
| 700 | + symbolic_alignment: RefCell::new(FxHashMap::default()), |
701 | 701 | } |
702 | 702 | } |
703 | 703 |
|
@@ -810,6 +810,7 @@ impl VisitProvenance for MiriMachine<'_, '_> { |
810 | 810 | collect_leak_backtraces: _, |
811 | 811 | allocation_spans: _, |
812 | 812 | const_cache: _, |
| 813 | + symbolic_alignment: _, |
813 | 814 | } = self; |
814 | 815 |
|
815 | 816 | threads.visit_provenance(visit); |
@@ -893,9 +894,13 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> { |
893 | 894 | return None; |
894 | 895 | } |
895 | 896 | // Let's see which alignment we have been promised for this allocation. |
896 | | - let alloc_info = ecx.get_alloc_extra(alloc_id).unwrap(); // cannot fail since the allocation is live |
897 | | - let (promised_offset, promised_align) = |
898 | | - alloc_info.symbolic_alignment.get().unwrap_or((Size::ZERO, alloc_align)); |
| 897 | + let (promised_offset, promised_align) = ecx |
| 898 | + .machine |
| 899 | + .symbolic_alignment |
| 900 | + .borrow() |
| 901 | + .get(&alloc_id) |
| 902 | + .copied() |
| 903 | + .unwrap_or((Size::ZERO, alloc_align)); |
899 | 904 | if promised_align < align { |
900 | 905 | // Definitely not enough. |
901 | 906 | Some(Misalignment { has: promised_align, required: align }) |
@@ -1132,7 +1137,6 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for MiriMachine<'mir, 'tcx> { |
1132 | 1137 | data_race: race_alloc, |
1133 | 1138 | weak_memory: buffer_alloc, |
1134 | 1139 | backtrace, |
1135 | | - symbolic_alignment: Cell::new(None), |
1136 | 1140 | }, |
1137 | 1141 | |ptr| ecx.global_base_pointer(ptr), |
1138 | 1142 | )?; |
|
0 commit comments