Skip to content

Commit 18e9187

Browse files
authored
Unrolled build for #145540
Rollup merge of #145540 - nia-e:prov-map-range, r=RalfJung interpret/allocation: get_range on ProvenanceMap Helper method to grab all provenances in a given address range for an allocation, making some logic in Miri nicer.
2 parents 69b76df + 7046ce8 commit 18e9187

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

compiler/rustc_middle/src/mir/interpret/allocation/provenance_map.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
120120
}
121121
}
122122

123+
/// Gets the provenances of all bytes (including from pointers) in a range.
124+
pub fn get_range(
125+
&self,
126+
cx: &impl HasDataLayout,
127+
range: AllocRange,
128+
) -> impl Iterator<Item = Prov> {
129+
let ptr_provs = self.range_ptrs_get(range, cx).iter().map(|(_, p)| *p);
130+
let byte_provs = self.range_bytes_get(range).iter().map(|(_, (p, _))| *p);
131+
ptr_provs.chain(byte_provs)
132+
}
133+
123134
/// Attempt to merge per-byte provenance back into ptr chunks, if the right fragments
124135
/// sit next to each other. Return `false` is that is not possible due to partial pointers.
125136
pub fn merge_bytes(&mut self, cx: &impl HasDataLayout) -> bool {

src/tools/miri/src/shims/native_lib/mod.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
242242

243243
match evt {
244244
AccessEvent::Read(_) => {
245-
// FIXME: ProvenanceMap should have something like get_range().
246-
let p_map = alloc.provenance();
247-
for idx in overlap {
248-
// If a provenance was read by the foreign code, expose it.
249-
if let Some((prov, _idx)) = p_map.get_byte(Size::from_bytes(idx), this)
250-
{
251-
this.expose_provenance(prov)?;
252-
}
245+
// If a provenance was read by the foreign code, expose it.
246+
for prov in alloc.provenance().get_range(this, overlap.into()) {
247+
this.expose_provenance(prov)?;
253248
}
254249
}
255250
AccessEvent::Write(_, certain) => {

0 commit comments

Comments
 (0)