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

Commit 59f9a91

Browse files
committed
handle get_alloc_extra the same throughout Stacked Borrows
1 parent 167e5dc commit 59f9a91

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
lines changed

src/intptrcast.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,21 @@ impl<'mir, 'tcx> GlobalStateInner {
9494
None
9595
}
9696

97-
pub fn expose_ptr(ecx: &mut MiriEvalContext<'mir, 'tcx>, alloc_id: AllocId, sb: SbTag) {
97+
pub fn expose_ptr(
98+
ecx: &mut MiriEvalContext<'mir, 'tcx>,
99+
alloc_id: AllocId,
100+
sb: SbTag,
101+
) -> InterpResult<'tcx> {
98102
let global_state = ecx.machine.intptrcast.get_mut();
99103
// In strict mode, we don't need this, so we can save some cycles by not tracking it.
100104
if global_state.provenance_mode != ProvenanceMode::Strict {
101105
trace!("Exposing allocation id {alloc_id:?}");
102106
global_state.exposed.insert(alloc_id);
103107
if ecx.machine.stacked_borrows.is_some() {
104-
ecx.expose_tag(alloc_id, sb);
108+
ecx.expose_tag(alloc_id, sb)?;
105109
}
106110
}
111+
Ok(())
107112
}
108113

109114
pub fn ptr_from_addr_transmute(

src/machine.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -754,15 +754,14 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
754754
ptr: Pointer<Self::Provenance>,
755755
) -> InterpResult<'tcx> {
756756
match ptr.provenance {
757-
Provenance::Concrete { alloc_id, sb } => {
758-
intptrcast::GlobalStateInner::expose_ptr(ecx, alloc_id, sb);
759-
}
757+
Provenance::Concrete { alloc_id, sb } =>
758+
intptrcast::GlobalStateInner::expose_ptr(ecx, alloc_id, sb),
760759
Provenance::Wildcard => {
761760
// No need to do anything for wildcard pointers as
762761
// their provenances have already been previously exposed.
762+
Ok(())
763763
}
764764
}
765-
Ok(())
766765
}
767766

768767
/// Convert a pointer with provenance into an allocation-offset pair,

src/stacked_borrows/mod.rs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -777,20 +777,31 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
777777
return Ok(())
778778
};
779779

780-
let extra = this.get_alloc_extra(alloc_id)?;
781-
let mut stacked_borrows = extra
782-
.stacked_borrows
783-
.as_ref()
784-
.expect("we should have Stacked Borrows data")
785-
.borrow_mut();
786-
stacked_borrows.history.log_creation(
787-
Some(orig_tag),
788-
new_tag,
789-
alloc_range(base_offset, size),
790-
current_span,
791-
);
792-
if protect {
793-
stacked_borrows.history.log_protector(orig_tag, new_tag, current_span);
780+
let (_size, _align, kind) = this.get_alloc_info(alloc_id);
781+
match kind {
782+
AllocKind::LiveData => {
783+
// This should have alloc_extra data, but `get_alloc_extra` can still fail
784+
// if converting this alloc_id from a global to a local one
785+
// uncovers a non-supported `extern static`.
786+
let extra = this.get_alloc_extra(alloc_id)?;
787+
let mut stacked_borrows = extra
788+
.stacked_borrows
789+
.as_ref()
790+
.expect("we should have Stacked Borrows data")
791+
.borrow_mut();
792+
stacked_borrows.history.log_creation(
793+
Some(orig_tag),
794+
new_tag,
795+
alloc_range(base_offset, size),
796+
current_span,
797+
);
798+
if protect {
799+
stacked_borrows.history.log_protector(orig_tag, new_tag, current_span);
800+
}
801+
}
802+
AllocKind::Function | AllocKind::Dead => {
803+
// No stacked borrows on these allocations.
804+
}
794805
}
795806
Ok(())
796807
};
@@ -1116,7 +1127,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
11161127
}
11171128

11181129
/// Mark the given tag as exposed. It was found on a pointer with the given AllocId.
1119-
fn expose_tag(&mut self, alloc_id: AllocId, tag: SbTag) {
1130+
fn expose_tag(&mut self, alloc_id: AllocId, tag: SbTag) -> InterpResult<'tcx> {
11201131
let this = self.eval_context_mut();
11211132

11221133
// Function pointers and dead objects don't have an alloc_extra so we ignore them.
@@ -1125,14 +1136,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
11251136
let (_size, _align, kind) = this.get_alloc_info(alloc_id);
11261137
match kind {
11271138
AllocKind::LiveData => {
1128-
// This should have alloc_extra data.
1129-
let alloc_extra = this.get_alloc_extra(alloc_id).unwrap();
1139+
// This should have alloc_extra data, but `get_alloc_extra` can still fail
1140+
// if converting this alloc_id from a global to a local one
1141+
// uncovers a non-supported `extern static`.
1142+
let alloc_extra = this.get_alloc_extra(alloc_id)?;
11301143
trace!("Stacked Borrows tag {tag:?} exposed in {alloc_id:?}");
11311144
alloc_extra.stacked_borrows.as_ref().unwrap().borrow_mut().exposed_tags.insert(tag);
11321145
}
11331146
AllocKind::Function | AllocKind::Dead => {
11341147
// No stacked borrows on these allocations.
11351148
}
11361149
}
1150+
Ok(())
11371151
}
11381152
}

0 commit comments

Comments
 (0)