Skip to content

Commit 424a749

Browse files
committed
Auto merge of #55179 - bjorn3:miri_public_op_field, r=RalfJung
Give OpTy access to locals for priroda r? @oli-obk
2 parents 12a88a6 + b178553 commit 424a749

File tree

5 files changed

+31
-19
lines changed

5 files changed

+31
-19
lines changed

src/librustc_mir/interpret/eval_context.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,11 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
324324

325325
pub fn layout_of_local(
326326
&self,
327-
frame: usize,
327+
frame: &Frame<'mir, 'tcx, M::PointerTag>,
328328
local: mir::Local
329329
) -> EvalResult<'tcx, TyLayout<'tcx>> {
330-
let local_ty = self.stack[frame].mir.local_decls[local].ty;
331-
let local_ty = self.monomorphize(
332-
local_ty,
333-
self.stack[frame].instance.substs
334-
);
330+
let local_ty = frame.mir.local_decls[local].ty;
331+
let local_ty = self.monomorphize(local_ty, frame.instance.substs);
335332
self.layout_of(local_ty)
336333
}
337334

@@ -579,7 +576,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
579576
assert!(local != mir::RETURN_PLACE, "Cannot make return place live");
580577
trace!("{:?} is now live", local);
581578

582-
let layout = self.layout_of_local(self.cur_frame(), local)?;
579+
let layout = self.layout_of_local(self.frame(), local)?;
583580
let init = LocalValue::Live(self.uninit_operand(layout)?);
584581
// StorageLive *always* kills the value that's currently stored
585582
Ok(mem::replace(&mut self.frame_mut().locals[local], init))
@@ -733,4 +730,3 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc
733730
truncate(value, ty.size)
734731
}
735732
}
736-

src/librustc_mir/interpret/memory.rs

+5
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,11 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
603603
self.dump_allocs(leaks);
604604
n
605605
}
606+
607+
/// This is used by [priroda](https://github.com/oli-obk/priroda)
608+
pub fn alloc_map(&self) -> &M::MemoryMap {
609+
&self.alloc_map
610+
}
606611
}
607612

608613
/// Byte accessors

src/librustc_mir/interpret/operand.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,22 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
571571
})
572572
}
573573

574+
/// This is used by [priroda](https://github.com/oli-obk/priroda) to get an OpTy from a local
575+
///
576+
/// When you know the layout of the local in advance, you can pass it as last argument
577+
pub fn access_local(
578+
&self,
579+
frame: &super::Frame<'mir, 'tcx, M::PointerTag>,
580+
local: mir::Local,
581+
layout: Option<TyLayout<'tcx>>,
582+
) -> EvalResult<'tcx, OpTy<'tcx, M::PointerTag>> {
583+
assert_ne!(local, mir::RETURN_PLACE);
584+
let op = *frame.locals[local].access()?;
585+
let layout = from_known_layout(layout,
586+
|| self.layout_of_local(frame, local))?;
587+
Ok(OpTy { op, layout })
588+
}
589+
574590
// Evaluate a place with the goal of reading from it. This lets us sometimes
575591
// avoid allocations. If you already know the layout, you can pass it in
576592
// to avoid looking it up again.
@@ -582,12 +598,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
582598
use rustc::mir::Place::*;
583599
let op = match *mir_place {
584600
Local(mir::RETURN_PLACE) => return err!(ReadFromReturnPointer),
585-
Local(local) => {
586-
let op = *self.frame().locals[local].access()?;
587-
let layout = from_known_layout(layout,
588-
|| self.layout_of_local(self.cur_frame(), local))?;
589-
OpTy { op, layout }
590-
},
601+
Local(local) => self.access_local(self.frame(), local, layout)?,
591602

592603
Projection(ref proj) => {
593604
let op = self.eval_place_to_op(&proj.base, None)?;

src/librustc_mir/interpret/place.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ where
588588
// their layout on return.
589589
PlaceTy {
590590
place: *return_place,
591-
layout: self.layout_of_local(self.cur_frame(), mir::RETURN_PLACE)?,
591+
layout: self.layout_of_local(self.frame(), mir::RETURN_PLACE)?,
592592
},
593593
None => return err!(InvalidNullPointerUsage),
594594
},
@@ -597,7 +597,7 @@ where
597597
frame: self.cur_frame(),
598598
local,
599599
},
600-
layout: self.layout_of_local(self.cur_frame(), local)?,
600+
layout: self.layout_of_local(self.frame(), local)?,
601601
},
602602

603603
Projection(ref proj) => {
@@ -856,7 +856,7 @@ where
856856
// We need the layout of the local. We can NOT use the layout we got,
857857
// that might e.g. be an inner field of a struct with `Scalar` layout,
858858
// that has different alignment than the outer field.
859-
let local_layout = self.layout_of_local(frame, local)?;
859+
let local_layout = self.layout_of_local(&self.stack[frame], local)?;
860860
let ptr = self.allocate(local_layout, MemoryKind::Stack)?;
861861
// We don't have to validate as we can assume the local
862862
// was already valid for its type.

src/librustc_mir/interpret/terminator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
310310
mir.spread_arg,
311311
mir.args_iter()
312312
.map(|local|
313-
(local, self.layout_of_local(self.cur_frame(), local).unwrap().ty)
313+
(local, self.layout_of_local(self.frame(), local).unwrap().ty)
314314
)
315315
.collect::<Vec<_>>()
316316
);
@@ -380,7 +380,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
380380
}
381381
} else {
382382
let callee_layout =
383-
self.layout_of_local(self.cur_frame(), mir::RETURN_PLACE)?;
383+
self.layout_of_local(self.frame(), mir::RETURN_PLACE)?;
384384
if !callee_layout.abi.is_uninhabited() {
385385
return err!(FunctionRetMismatch(
386386
self.tcx.types.never, callee_layout.ty

0 commit comments

Comments
 (0)