Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4fbb284

Browse files
committed
implement 'delimited' expose tracking so we still detect some UB
1 parent 8d6fdaa commit 4fbb284

13 files changed

+293
-125
lines changed

src/diagnostics.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::ty;
88
use rustc_span::{source_map::DUMMY_SP, Span, SpanData, Symbol};
99

1010
use crate::helpers::HexRange;
11-
use crate::stacked_borrows::{diagnostics::TagHistory, AccessKind, SbTag};
11+
use crate::stacked_borrows::{diagnostics::TagHistory, AccessKind};
1212
use crate::*;
1313

1414
/// Details of premature program termination.
@@ -61,9 +61,9 @@ impl MachineStopType for TerminationInfo {}
6161
/// Miri specific diagnostics
6262
pub enum NonHaltingDiagnostic {
6363
CreatedPointerTag(NonZeroU64),
64-
/// This `Item` was popped from the borrow stack, either due to a grant of
65-
/// `AccessKind` to `SbTag` or a deallocation when the second argument is `None`.
66-
PoppedPointerTag(Item, Option<(SbTag, AccessKind)>),
64+
/// This `Item` was popped from the borrow stack, either due to an access with the given tag or
65+
/// a deallocation when the second argument is `None`.
66+
PoppedPointerTag(Item, Option<(SbTagExtra, AccessKind)>),
6767
CreatedCallId(CallId),
6868
CreatedAlloc(AllocId),
6969
FreedAlloc(AllocId),

src/intptrcast.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ impl<'mir, 'tcx> GlobalStateInner {
142142
// Determine the allocation this points to at cast time.
143143
let alloc_id = Self::alloc_id_from_addr(ecx, addr);
144144
Pointer::new(
145-
alloc_id.map(|alloc_id| {
146-
Tag::Concrete(ConcreteTag { alloc_id, sb: SbTag::Untagged })
147-
}),
145+
alloc_id.map(|alloc_id| Tag::Concrete { alloc_id, sb: SbTag::Untagged }),
148146
Size::from_bytes(addr),
149147
)
150148
}
@@ -222,8 +220,8 @@ impl<'mir, 'tcx> GlobalStateInner {
222220
) -> Option<(AllocId, Size)> {
223221
let (tag, addr) = ptr.into_parts(); // addr is absolute (Tag provenance)
224222

225-
let alloc_id = if let Tag::Concrete(concrete) = tag {
226-
concrete.alloc_id
223+
let alloc_id = if let Tag::Concrete { alloc_id, .. } = tag {
224+
alloc_id
227225
} else {
228226
// A wildcard pointer.
229227
assert_eq!(ecx.machine.intptrcast.borrow().provenance_mode, ProvenanceMode::Permissive);

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(io_error_more)]
88
#![feature(yeet_expr)]
99
#![feature(is_some_with)]
10+
#![feature(nonzero_ops)]
1011
#![warn(rust_2018_idioms)]
1112
#![allow(
1213
clippy::collapsible_else_if,
@@ -81,15 +82,15 @@ pub use crate::eval::{
8182
pub use crate::helpers::{CurrentSpan, EvalContextExt as HelpersEvalContextExt};
8283
pub use crate::intptrcast::ProvenanceMode;
8384
pub use crate::machine::{
84-
AllocExtra, ConcreteTag, Evaluator, FrameData, MiriEvalContext, MiriEvalContextExt,
85-
MiriMemoryKind, Tag, NUM_CPUS, PAGE_SIZE, STACK_ADDR, STACK_SIZE,
85+
AllocExtra, Evaluator, FrameData, MiriEvalContext, MiriEvalContextExt, MiriMemoryKind, Tag,
86+
NUM_CPUS, PAGE_SIZE, STACK_ADDR, STACK_SIZE,
8687
};
8788
pub use crate::mono_hash_map::MonoHashMap;
8889
pub use crate::operator::EvalContextExt as OperatorEvalContextExt;
8990
pub use crate::range_map::RangeMap;
9091
pub use crate::stacked_borrows::{
91-
CallId, EvalContextExt as StackedBorEvalContextExt, Item, Permission, PtrId, SbTag, Stack,
92-
Stacks,
92+
CallId, EvalContextExt as StackedBorEvalContextExt, Item, Permission, PtrId, SbTag, SbTagExtra,
93+
Stack, Stacks,
9394
};
9495
pub use crate::sync::{CondvarId, EvalContextExt as SyncEvalContextExt, MutexId, RwLockId};
9596
pub use crate::thread::{

src/machine.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,14 @@ impl fmt::Display for MiriMemoryKind {
130130
/// Pointer provenance (tag).
131131
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
132132
pub enum Tag {
133-
Concrete(ConcreteTag),
133+
Concrete {
134+
alloc_id: AllocId,
135+
/// Stacked Borrows tag.
136+
sb: SbTag,
137+
},
134138
Wildcard,
135139
}
136140

137-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
138-
pub struct ConcreteTag {
139-
pub alloc_id: AllocId,
140-
/// Stacked Borrows tag.
141-
pub sb: SbTag,
142-
}
143-
144141
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
145142
static_assert_size!(Pointer<Tag>, 24);
146143
// #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
@@ -160,15 +157,15 @@ impl Provenance for Tag {
160157
write!(f, "0x{:x}", addr.bytes())?;
161158

162159
match tag {
163-
Tag::Concrete(tag) => {
160+
Tag::Concrete { alloc_id, sb } => {
164161
// Forward `alternate` flag to `alloc_id` printing.
165162
if f.alternate() {
166-
write!(f, "[{:#?}]", tag.alloc_id)?;
163+
write!(f, "[{:#?}]", alloc_id)?;
167164
} else {
168-
write!(f, "[{:?}]", tag.alloc_id)?;
165+
write!(f, "[{:?}]", alloc_id)?;
169166
}
170167
// Print Stacked Borrows tag.
171-
write!(f, "{:?}", tag.sb)?;
168+
write!(f, "{:?}", sb)?;
172169
}
173170
Tag::Wildcard => {
174171
write!(f, "[Wildcard]")?;
@@ -180,7 +177,7 @@ impl Provenance for Tag {
180177

181178
fn get_alloc_id(self) -> Option<AllocId> {
182179
match self {
183-
Tag::Concrete(concrete) => Some(concrete.alloc_id),
180+
Tag::Concrete { alloc_id, .. } => Some(alloc_id),
184181
Tag::Wildcard => None,
185182
}
186183
}
@@ -489,8 +486,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
489486
type AllocExtra = AllocExtra;
490487

491488
type PointerTag = Tag;
492-
// `None` represents a wildcard pointer.
493-
type TagExtra = Option<SbTag>;
489+
type TagExtra = SbTagExtra;
494490

495491
type MemoryMap =
496492
MonoHashMap<AllocId, (MemoryKind<MiriMemoryKind>, Allocation<Tag, Self::AllocExtra>)>;
@@ -683,7 +679,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
683679
SbTag::Untagged
684680
};
685681
Pointer::new(
686-
Tag::Concrete(ConcreteTag { alloc_id: ptr.provenance, sb: sb_tag }),
682+
Tag::Concrete { alloc_id: ptr.provenance, sb: sb_tag },
687683
Size::from_bytes(absolute_addr),
688684
)
689685
}
@@ -709,7 +705,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
709705
ptr: Pointer<Self::PointerTag>,
710706
) -> InterpResult<'tcx> {
711707
match ptr.provenance {
712-
Tag::Concrete(ConcreteTag { alloc_id, sb }) => {
708+
Tag::Concrete { alloc_id, sb } => {
713709
intptrcast::GlobalStateInner::expose_ptr(ecx, alloc_id, sb);
714710
}
715711
Tag::Wildcard => {
@@ -730,8 +726,8 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
730726

731727
rel.map(|(alloc_id, size)| {
732728
let sb = match ptr.provenance {
733-
Tag::Concrete(ConcreteTag { sb, .. }) => Some(sb),
734-
Tag::Wildcard => None,
729+
Tag::Concrete { sb, .. } => SbTagExtra::Concrete(sb),
730+
Tag::Wildcard => SbTagExtra::Wildcard,
735731
};
736732
(alloc_id, size, sb)
737733
})

0 commit comments

Comments
 (0)