Skip to content

Commit f03b6fb

Browse files
committed
interpret/allocation: get_range on ProvenanceMap
1 parent 6ba0ce4 commit f03b6fb

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
@@ -148,6 +148,17 @@ impl<Prov: Provenance> ProvenanceMap<Prov> {
148148
true
149149
}
150150

151+
/// Gets the provenances of all bytes (including from pointers) in a range.
152+
pub fn get_range(
153+
&self,
154+
cx: &impl HasDataLayout,
155+
range: AllocRange,
156+
) -> impl Iterator<Item = (Size, Prov)> {
157+
let ptr_provs = self.range_ptrs_get(range, cx).to_owned();
158+
let byte_provs = self.range_bytes_get(range).into_iter().map(|&(s, (p, _))| (s, p));
159+
ptr_provs.into_iter().chain(byte_provs)
160+
}
161+
151162
/// Check if there is ptr-sized provenance at the given index.
152163
/// Does not mean anything for bytewise provenance! But can be useful as an optimization.
153164
pub fn get_ptr(&self, offset: Size) -> Option<Prov> {

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)