Skip to content

Commit f79f31d

Browse files
committed
adjust for rustc changes; normalize mplace before doing freeze-sensitive visit
1 parent dd6cf30 commit f79f31d

File tree

4 files changed

+26
-31
lines changed

4 files changed

+26
-31
lines changed

src/eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>(
136136
let place = ecx.mplace_field(argvs_place, idx as u64)?;
137137
ecx.write_scalar(Scalar::Ptr(arg), place.into())?;
138138
}
139-
ecx.memory_mut().mark_immutable(argvs_place.to_ptr()?.alloc_id)?;
139+
ecx.memory_mut().mark_immutable(argvs_place.ptr.assert_ptr().alloc_id)?;
140140
// Write a pointer to that place as the argument.
141141
let argv = argvs_place.ptr;
142142
ecx.write_scalar(argv, dest)?;

src/helpers.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,36 +116,33 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
116116
.map(|(size, _)| size)
117117
.unwrap_or_else(|| place.layout.size)
118118
);
119-
assert!(size.bytes() > 0);
119+
let place = this.normalize_mplace_ptr(place)?;
120120
// Store how far we proceeded into the place so far. Everything to the left of
121121
// this offset has already been handled, in the sense that the frozen parts
122122
// have had `action` called on them.
123-
let mut end_ptr = place.ptr;
123+
let mut end_ptr = place.ptr.assert_ptr();
124124
// Called when we detected an `UnsafeCell` at the given offset and size.
125125
// Calls `action` and advances `end_ptr`.
126126
let mut unsafe_cell_action = |unsafe_cell_ptr: Scalar<Tag>, unsafe_cell_size: Size| {
127-
if unsafe_cell_size != Size::ZERO {
128-
debug_assert_eq!(unsafe_cell_ptr.to_ptr().unwrap().alloc_id,
129-
end_ptr.to_ptr().unwrap().alloc_id);
130-
debug_assert_eq!(unsafe_cell_ptr.to_ptr().unwrap().tag,
131-
end_ptr.to_ptr().unwrap().tag);
132-
}
127+
let unsafe_cell_ptr = unsafe_cell_ptr.assert_ptr();
128+
debug_assert_eq!(unsafe_cell_ptr.alloc_id, end_ptr.alloc_id);
129+
debug_assert_eq!(unsafe_cell_ptr.tag, end_ptr.tag);
133130
// We assume that we are given the fields in increasing offset order,
134131
// and nothing else changes.
135-
let unsafe_cell_offset = unsafe_cell_ptr.get_ptr_offset(this);
136-
let end_offset = end_ptr.get_ptr_offset(this);
132+
let unsafe_cell_offset = unsafe_cell_ptr.offset;
133+
let end_offset = end_ptr.offset;
137134
assert!(unsafe_cell_offset >= end_offset);
138135
let frozen_size = unsafe_cell_offset - end_offset;
139136
// Everything between the end_ptr and this `UnsafeCell` is frozen.
140137
if frozen_size != Size::ZERO {
141-
action(end_ptr.to_ptr()?, frozen_size, /*frozen*/true)?;
138+
action(end_ptr, frozen_size, /*frozen*/true)?;
142139
}
143140
// This `UnsafeCell` is NOT frozen.
144141
if unsafe_cell_size != Size::ZERO {
145-
action(unsafe_cell_ptr.to_ptr()?, unsafe_cell_size, /*frozen*/false)?;
142+
action(unsafe_cell_ptr, unsafe_cell_size, /*frozen*/false)?;
146143
}
147144
// Update end end_ptr.
148-
end_ptr = unsafe_cell_ptr.ptr_wrapping_offset(unsafe_cell_size, this);
145+
end_ptr = unsafe_cell_ptr.wrapping_offset(unsafe_cell_size, this);
149146
// Done
150147
Ok(())
151148
};
@@ -234,7 +231,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
234231
layout::FieldPlacement::Arbitrary { .. } => {
235232
// Gather the subplaces and sort them before visiting.
236233
let mut places = fields.collect::<InterpResult<'tcx, Vec<MPlaceTy<'tcx, Tag>>>>()?;
237-
places.sort_by_key(|place| place.ptr.get_ptr_offset(self.ecx()));
234+
places.sort_by_key(|place| place.ptr.assert_ptr().offset);
238235
self.walk_aggregate(place, places.into_iter().map(Ok))
239236
}
240237
layout::FieldPlacement::Union { .. } => {

src/shims/foreign_items.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -842,13 +842,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
842842
},
843843
"GetSystemInfo" => {
844844
let system_info = this.deref_operand(args[0])?;
845-
let (system_info_ptr, align) = system_info.to_scalar_ptr_align();
846-
let system_info_ptr = this.memory()
847-
.check_ptr_access(
848-
system_info_ptr,
849-
system_info.layout.size,
850-
align,
851-
)?
845+
let system_info_ptr = this.check_mplace_access(system_info, None)?
852846
.expect("cannot be a ZST");
853847
// Initialize with `0`.
854848
this.memory_mut().get_mut(system_info_ptr.alloc_id)?

src/shims/intrinsics.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,17 +166,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
166166
let elem_size = elem_layout.size.bytes();
167167
let count = this.read_scalar(args[2])?.to_usize(this)?;
168168
let elem_align = elem_layout.align.abi;
169-
// erase tags: this is a raw ptr operation
169+
170+
let size = Size::from_bytes(count * elem_size);
170171
let src = this.read_scalar(args[0])?.not_undef()?;
172+
let src = this.memory().check_ptr_access(src, size, elem_align)?;
171173
let dest = this.read_scalar(args[1])?.not_undef()?;
172-
this.memory_mut().copy(
173-
src,
174-
elem_align,
175-
dest,
176-
elem_align,
177-
Size::from_bytes(count * elem_size),
178-
intrinsic_name.ends_with("_nonoverlapping"),
179-
)?;
174+
let dest = this.memory().check_ptr_access(dest, size, elem_align)?;
175+
176+
if let (Some(src), Some(dest)) = (src, dest) {
177+
this.memory_mut().copy(
178+
src,
179+
dest,
180+
size,
181+
intrinsic_name.ends_with("_nonoverlapping"),
182+
)?;
183+
}
180184
}
181185

182186
"discriminant_value" => {

0 commit comments

Comments
 (0)