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

Commit 9e38dc4

Browse files
committed
Move and rename offset_and_layout_to_place to deref_operand_and_offset
1 parent 10d978c commit 9e38dc4

File tree

4 files changed

+26
-34
lines changed

4 files changed

+26
-34
lines changed

src/data_race.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ use rustc_middle::{mir, ty::layout::TyAndLayout};
7373
use rustc_target::abi::Size;
7474

7575
use crate::{
76-
AllocId, AllocRange, ImmTy, Immediate, InterpResult, MPlaceTy, MemPlaceMeta, MemoryKind,
77-
MiriEvalContext, MiriEvalContextExt, MiriMemoryKind, OpTy, Pointer, RangeMap, Scalar,
78-
ScalarMaybeUninit, Tag, ThreadId, VClock, VTimestamp, VectorIdx,
76+
AllocId, AllocRange, HelpersEvalContextExt, ImmTy, Immediate, InterpResult, MPlaceTy,
77+
MemoryKind, MiriEvalContext, MiriEvalContextExt, MiriMemoryKind, OpTy, Pointer, RangeMap,
78+
Scalar, ScalarMaybeUninit, Tag, ThreadId, VClock, VTimestamp, VectorIdx,
7979
};
8080

8181
pub type AllocExtra = VClockAlloc;
@@ -441,23 +441,6 @@ impl MemoryCellClocks {
441441
/// Evaluation context extensions.
442442
impl<'mir, 'tcx: 'mir> EvalContextExt<'mir, 'tcx> for MiriEvalContext<'mir, 'tcx> {}
443443
pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
444-
/// Calculates the MPlaceTy given the offset and layout of an access on an operand
445-
fn offset_and_layout_to_place(
446-
&self,
447-
op: &OpTy<'tcx, Tag>,
448-
offset: u64,
449-
layout: TyAndLayout<'tcx>,
450-
) -> InterpResult<'tcx, MPlaceTy<'tcx, Tag>> {
451-
let this = self.eval_context_ref();
452-
let op_place = this.deref_operand(op)?;
453-
let offset = Size::from_bytes(offset);
454-
455-
// Ensure that the access is within bounds.
456-
assert!(op_place.layout.size >= offset + layout.size);
457-
let value_place = op_place.offset(offset, MemPlaceMeta::None, layout, this)?;
458-
Ok(value_place)
459-
}
460-
461444
/// Atomic variant of read_scalar_at_offset.
462445
fn read_scalar_at_offset_atomic(
463446
&self,
@@ -467,7 +450,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
467450
atomic: AtomicReadOp,
468451
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
469452
let this = self.eval_context_ref();
470-
let value_place = this.offset_and_layout_to_place(op, offset, layout)?;
453+
let value_place = this.deref_operand_and_offset(op, offset, layout)?;
471454
this.read_scalar_atomic(&value_place, atomic)
472455
}
473456

@@ -481,7 +464,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: MiriEvalContextExt<'mir, 'tcx> {
481464
atomic: AtomicWriteOp,
482465
) -> InterpResult<'tcx> {
483466
let this = self.eval_context_mut();
484-
let value_place = this.offset_and_layout_to_place(op, offset, layout)?;
467+
let value_place = this.deref_operand_and_offset(op, offset, layout)?;
485468
this.write_scalar_atomic(value.into(), &value_place, atomic)
486469
}
487470

src/helpers.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -597,18 +597,31 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
597597
}
598598
}
599599

600-
fn read_scalar_at_offset(
600+
/// Calculates the MPlaceTy given the offset and layout of an access on an operand
601+
fn deref_operand_and_offset(
601602
&self,
602603
op: &OpTy<'tcx, Tag>,
603604
offset: u64,
604605
layout: TyAndLayout<'tcx>,
605-
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
606+
) -> InterpResult<'tcx, MPlaceTy<'tcx, Tag>> {
606607
let this = self.eval_context_ref();
607608
let op_place = this.deref_operand(op)?;
608609
let offset = Size::from_bytes(offset);
609-
// Ensure that the following read at an offset is within bounds
610+
611+
// Ensure that the access is within bounds.
610612
assert!(op_place.layout.size >= offset + layout.size);
611613
let value_place = op_place.offset(offset, MemPlaceMeta::None, layout, this)?;
614+
Ok(value_place)
615+
}
616+
617+
fn read_scalar_at_offset(
618+
&self,
619+
op: &OpTy<'tcx, Tag>,
620+
offset: u64,
621+
layout: TyAndLayout<'tcx>,
622+
) -> InterpResult<'tcx, ScalarMaybeUninit<Tag>> {
623+
let this = self.eval_context_ref();
624+
let value_place = this.deref_operand_and_offset(op, offset, layout)?;
612625
this.read_scalar(&value_place.into())
613626
}
614627

@@ -620,11 +633,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
620633
layout: TyAndLayout<'tcx>,
621634
) -> InterpResult<'tcx, ()> {
622635
let this = self.eval_context_mut();
623-
let op_place = this.deref_operand(op)?;
624-
let offset = Size::from_bytes(offset);
625-
// Ensure that the following read at an offset is within bounds
626-
assert!(op_place.layout.size >= offset + layout.size);
627-
let value_place = op_place.offset(offset, MemPlaceMeta::None, layout, this)?;
636+
let value_place = this.deref_operand_and_offset(op, offset, layout)?;
628637
this.write_scalar(value, &value_place.into())
629638
}
630639

src/shims/posix/sync.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn mutex_get_or_create_id<'mir, 'tcx: 'mir>(
112112
ecx: &mut MiriEvalContext<'mir, 'tcx>,
113113
mutex_op: &OpTy<'tcx, Tag>,
114114
) -> InterpResult<'tcx, MutexId> {
115-
let value_place = ecx.offset_and_layout_to_place(mutex_op, 4, ecx.machine.layouts.u32)?;
115+
let value_place = ecx.deref_operand_and_offset(mutex_op, 4, ecx.machine.layouts.u32)?;
116116

117117
ecx.mutex_get_or_create(|ecx, next_id| {
118118
let (old, success) = ecx
@@ -168,7 +168,7 @@ fn rwlock_get_or_create_id<'mir, 'tcx: 'mir>(
168168
ecx: &mut MiriEvalContext<'mir, 'tcx>,
169169
rwlock_op: &OpTy<'tcx, Tag>,
170170
) -> InterpResult<'tcx, RwLockId> {
171-
let value_place = ecx.offset_and_layout_to_place(rwlock_op, 4, ecx.machine.layouts.u32)?;
171+
let value_place = ecx.deref_operand_and_offset(rwlock_op, 4, ecx.machine.layouts.u32)?;
172172

173173
ecx.rwlock_get_or_create(|ecx, next_id| {
174174
let (old, success) = ecx
@@ -252,7 +252,7 @@ fn cond_get_or_create_id<'mir, 'tcx: 'mir>(
252252
ecx: &mut MiriEvalContext<'mir, 'tcx>,
253253
cond_op: &OpTy<'tcx, Tag>,
254254
) -> InterpResult<'tcx, CondvarId> {
255-
let value_place = ecx.offset_and_layout_to_place(cond_op, 4, ecx.machine.layouts.u32)?;
255+
let value_place = ecx.deref_operand_and_offset(cond_op, 4, ecx.machine.layouts.u32)?;
256256

257257
ecx.condvar_get_or_create(|ecx, next_id| {
258258
let (old, success) = ecx

src/shims/windows/sync.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn srwlock_get_or_create_id<'mir, 'tcx: 'mir>(
77
ecx: &mut MiriEvalContext<'mir, 'tcx>,
88
lock_op: &OpTy<'tcx, Tag>,
99
) -> InterpResult<'tcx, RwLockId> {
10-
let value_place = ecx.offset_and_layout_to_place(lock_op, 0, ecx.machine.layouts.u32)?;
10+
let value_place = ecx.deref_operand_and_offset(lock_op, 0, ecx.machine.layouts.u32)?;
1111

1212
ecx.rwlock_get_or_create(|ecx, next_id| {
1313
let (old, success) = ecx

0 commit comments

Comments
 (0)