Skip to content

Commit ac34812

Browse files
committed
make Miri build again with rustc provenance changes
1 parent da45adc commit ac34812

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

src/diagnostics.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,14 @@ pub fn report_error<'tcx, 'mir>(
224224
let helps = match e.kind() {
225225
Unsupported(
226226
UnsupportedOpInfo::ThreadLocalStatic(_) |
227-
UnsupportedOpInfo::ReadExternStatic(_)
227+
UnsupportedOpInfo::ReadExternStatic(_) |
228+
UnsupportedOpInfo::PartialPointerOverwrite(_) | // we make memory uninit instead
229+
UnsupportedOpInfo::ReadPointerAsBytes
228230
) =>
229231
panic!("Error should never be raised by Miri: {kind:?}", kind = e.kind()),
230232
Unsupported(
231233
UnsupportedOpInfo::Unsupported(_) |
232-
UnsupportedOpInfo::PartialPointerOverwrite(_) |
233-
UnsupportedOpInfo::ReadPointerAsBytes
234+
UnsupportedOpInfo::PartialPointerCopy(_)
234235
) =>
235236
vec![(None, format!("this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support"))],
236237
UndefinedBehavior(UndefinedBehaviorInfo::AlignmentCheckFailed { .. })

src/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
757757
}
758758

759759
// Step 2: get the bytes.
760-
this.read_bytes_ptr(ptr, len)
760+
this.read_bytes_ptr_strip_provenance(ptr, len)
761761
}
762762

763763
fn read_wide_str(&self, mut ptr: Pointer<Option<Provenance>>) -> InterpResult<'tcx, Vec<u16>> {

src/machine.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ impl interpret::Provenance for Provenance {
205205
Provenance::Wildcard => None,
206206
}
207207
}
208+
209+
fn join(left: Option<Self>, right: Option<Self>) -> Option<Self> {
210+
match (left, right) {
211+
// If both are the *same* concrete tag, that is the result.
212+
(
213+
Some(Provenance::Concrete { alloc_id: left_alloc, sb: left_sb }),
214+
Some(Provenance::Concrete { alloc_id: right_alloc, sb: right_sb }),
215+
) if left_alloc == right_alloc && left_sb == right_sb => left,
216+
// If one side is a wildcard, the best possible outcome is that it is equal to the other
217+
// one, and we use that.
218+
(Some(Provenance::Wildcard), o) | (o, Some(Provenance::Wildcard)) => o,
219+
// Otherwise, fall back to `None`.
220+
_ => None,
221+
}
222+
}
208223
}
209224

210225
impl fmt::Debug for ProvenanceExtra {

src/shims/foreign_items.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
560560
let n = Size::from_bytes(this.read_scalar(n)?.to_machine_usize(this)?);
561561

562562
let result = {
563-
let left_bytes = this.read_bytes_ptr(left, n)?;
564-
let right_bytes = this.read_bytes_ptr(right, n)?;
563+
let left_bytes = this.read_bytes_ptr_strip_provenance(left, n)?;
564+
let right_bytes = this.read_bytes_ptr_strip_provenance(right, n)?;
565565

566566
use std::cmp::Ordering::*;
567567
match left_bytes.cmp(right_bytes) {
@@ -583,7 +583,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
583583
let val = val as u8;
584584

585585
if let Some(idx) = this
586-
.read_bytes_ptr(ptr, Size::from_bytes(num))?
586+
.read_bytes_ptr_strip_provenance(ptr, Size::from_bytes(num))?
587587
.iter()
588588
.rev()
589589
.position(|&c| c == val)
@@ -606,7 +606,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
606606
let val = val as u8;
607607

608608
let idx = this
609-
.read_bytes_ptr(ptr, Size::from_bytes(num))?
609+
.read_bytes_ptr_strip_provenance(ptr, Size::from_bytes(num))?
610610
.iter()
611611
.position(|&c| c == val);
612612
if let Some(idx) = idx {

src/shims/unix/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
761761
let communicate = this.machine.communicate();
762762

763763
if let Some(file_descriptor) = this.machine.file_handler.handles.get(&fd) {
764-
let bytes = this.read_bytes_ptr(buf, Size::from_bytes(count))?;
764+
let bytes = this.read_bytes_ptr_strip_provenance(buf, Size::from_bytes(count))?;
765765
let result =
766766
file_descriptor.write(communicate, bytes)?.map(|c| i64::try_from(c).unwrap());
767767
this.try_unwrap_io_result(result)

src/shims/windows/dlsym.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
7878
// stdout/stderr
7979
use std::io::{self, Write};
8080

81-
let buf_cont = this.read_bytes_ptr(buf, Size::from_bytes(u64::from(n)))?;
81+
let buf_cont =
82+
this.read_bytes_ptr_strip_provenance(buf, Size::from_bytes(u64::from(n)))?;
8283
let res = if this.machine.mute_stdout_stderr {
8384
Ok(buf_cont.len())
8485
} else if handle == -11 {

0 commit comments

Comments
 (0)