mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Undo questionable changes
This commit is contained in:
parent
66751ea73e
commit
98f30e833a
@ -167,7 +167,7 @@ pub(super) fn op_to_const<'tcx>(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
match immediate {
|
match immediate {
|
||||||
Left(mplace) => to_const_value(&mplace),
|
Left(ref mplace) => to_const_value(mplace),
|
||||||
// see comment on `let try_as_immediate` above
|
// see comment on `let try_as_immediate` above
|
||||||
Right(imm) => match *imm {
|
Right(imm) => match *imm {
|
||||||
_ if imm.layout.is_zst() => ConstValue::ZeroSized,
|
_ if imm.layout.is_zst() => ConstValue::ZeroSized,
|
||||||
|
@ -535,7 +535,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||||||
use rustc_middle::mir::Operand::*;
|
use rustc_middle::mir::Operand::*;
|
||||||
let op = match mir_op {
|
let op = match mir_op {
|
||||||
// FIXME: do some more logic on `move` to invalidate the old location
|
// FIXME: do some more logic on `move` to invalidate the old location
|
||||||
&(Copy(place) | Move(place)) => self.eval_place_to_op(place, layout)?,
|
&Copy(place) | &Move(place) => self.eval_place_to_op(place, layout)?,
|
||||||
|
|
||||||
Constant(constant) => {
|
Constant(constant) => {
|
||||||
let c =
|
let c =
|
||||||
|
@ -87,9 +87,9 @@ where
|
|||||||
field: usize,
|
field: usize,
|
||||||
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
|
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
|
||||||
let base = match base.as_mplace_or_imm() {
|
let base = match base.as_mplace_or_imm() {
|
||||||
Left(mplace) => {
|
Left(ref mplace) => {
|
||||||
// We can reuse the mplace field computation logic for indirect operands.
|
// We can reuse the mplace field computation logic for indirect operands.
|
||||||
let field = self.mplace_field(&mplace, field)?;
|
let field = self.mplace_field(mplace, field)?;
|
||||||
return Ok(field.into());
|
return Ok(field.into());
|
||||||
}
|
}
|
||||||
Right(value) => value,
|
Right(value) => value,
|
||||||
|
@ -22,20 +22,19 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||||||
terminator: &mir::Terminator<'tcx>,
|
terminator: &mir::Terminator<'tcx>,
|
||||||
) -> InterpResult<'tcx> {
|
) -> InterpResult<'tcx> {
|
||||||
use rustc_middle::mir::TerminatorKind::*;
|
use rustc_middle::mir::TerminatorKind::*;
|
||||||
match &terminator.kind {
|
match terminator.kind {
|
||||||
Return => {
|
Return => {
|
||||||
self.pop_stack_frame(/* unwinding */ false)?
|
self.pop_stack_frame(/* unwinding */ false)?
|
||||||
}
|
}
|
||||||
|
|
||||||
Goto { target } => self.go_to_block(*target),
|
Goto { target } => self.go_to_block(target),
|
||||||
|
|
||||||
SwitchInt { discr, targets } => {
|
SwitchInt { ref discr, ref targets } => {
|
||||||
let discr = self.read_immediate(&self.eval_operand(discr, None)?)?;
|
let discr = self.read_immediate(&self.eval_operand(discr, None)?)?;
|
||||||
trace!("SwitchInt({:?})", *discr);
|
trace!("SwitchInt({:?})", *discr);
|
||||||
|
|
||||||
// Branch to the `otherwise` case by default, if no match is found.
|
// Branch to the `otherwise` case by default, if no match is found.
|
||||||
let mut target_block = targets.otherwise();
|
let mut target_block = targets.otherwise();
|
||||||
|
|
||||||
for (const_int, target) in targets.iter() {
|
for (const_int, target) in targets.iter() {
|
||||||
// Compare using MIR BinOp::Eq, to also support pointer values.
|
// Compare using MIR BinOp::Eq, to also support pointer values.
|
||||||
// (Avoiding `self.binary_op` as that does some redundant layout computation.)
|
// (Avoiding `self.binary_op` as that does some redundant layout computation.)
|
||||||
@ -51,22 +50,27 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.go_to_block(target_block);
|
self.go_to_block(target_block);
|
||||||
}
|
}
|
||||||
|
|
||||||
Call { func, args, destination, target, cleanup, from_hir_call: _, fn_span: _ } => {
|
Call {
|
||||||
|
ref func,
|
||||||
|
ref args,
|
||||||
|
destination,
|
||||||
|
target,
|
||||||
|
ref cleanup,
|
||||||
|
from_hir_call: _,
|
||||||
|
fn_span: _,
|
||||||
|
} => {
|
||||||
let old_stack = self.frame_idx();
|
let old_stack = self.frame_idx();
|
||||||
let old_loc = self.frame().loc;
|
let old_loc = self.frame().loc;
|
||||||
let func = self.eval_operand(func, None)?;
|
let func = self.eval_operand(func, None)?;
|
||||||
let args = self.eval_operands(args)?;
|
let args = self.eval_operands(args)?;
|
||||||
|
|
||||||
let fn_sig_binder = func.layout.ty.fn_sig(*self.tcx);
|
let fn_sig_binder = func.layout.ty.fn_sig(*self.tcx);
|
||||||
let fn_sig =
|
let fn_sig =
|
||||||
self.tcx.normalize_erasing_late_bound_regions(self.param_env, fn_sig_binder);
|
self.tcx.normalize_erasing_late_bound_regions(self.param_env, fn_sig_binder);
|
||||||
let extra_args = &args[fn_sig.inputs().len()..];
|
let extra_args = &args[fn_sig.inputs().len()..];
|
||||||
let extra_args = self.tcx.mk_type_list(extra_args.iter().map(|arg| arg.layout.ty));
|
let extra_args = self.tcx.mk_type_list(extra_args.iter().map(|arg| arg.layout.ty));
|
||||||
|
|
||||||
let (fn_val, fn_abi, with_caller_location) = match *func.layout.ty.kind() {
|
let (fn_val, fn_abi, with_caller_location) = match *func.layout.ty.kind() {
|
||||||
ty::FnPtr(_sig) => {
|
ty::FnPtr(_sig) => {
|
||||||
let fn_ptr = self.read_pointer(&func)?;
|
let fn_ptr = self.read_pointer(&func)?;
|
||||||
@ -89,14 +93,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
let destination = self.eval_place(*destination)?;
|
let destination = self.eval_place(destination)?;
|
||||||
self.eval_fn_call(
|
self.eval_fn_call(
|
||||||
fn_val,
|
fn_val,
|
||||||
(fn_sig.abi, fn_abi),
|
(fn_sig.abi, fn_abi),
|
||||||
&args,
|
&args,
|
||||||
with_caller_location,
|
with_caller_location,
|
||||||
&destination,
|
&destination,
|
||||||
*target,
|
target,
|
||||||
match (cleanup, fn_abi.can_unwind) {
|
match (cleanup, fn_abi.can_unwind) {
|
||||||
(Some(cleanup), true) => StackPopUnwind::Cleanup(*cleanup),
|
(Some(cleanup), true) => StackPopUnwind::Cleanup(*cleanup),
|
||||||
(None, true) => StackPopUnwind::Skip,
|
(None, true) => StackPopUnwind::Skip,
|
||||||
@ -110,7 +114,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&Drop { place, target, unwind } => {
|
Drop { place, target, unwind } => {
|
||||||
let frame = self.frame();
|
let frame = self.frame();
|
||||||
let ty = place.ty(&frame.body.local_decls, *self.tcx).ty;
|
let ty = place.ty(&frame.body.local_decls, *self.tcx).ty;
|
||||||
let ty = self.subst_from_frame_and_normalize_erasing_regions(frame, ty)?;
|
let ty = self.subst_from_frame_and_normalize_erasing_regions(frame, ty)?;
|
||||||
@ -128,19 +132,18 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||||||
self.drop_in_place(&place, instance, target, unwind)?;
|
self.drop_in_place(&place, instance, target, unwind)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert { cond, expected, msg, target, cleanup } => {
|
Assert { ref cond, expected, ref msg, target, cleanup } => {
|
||||||
let cond_val = self.read_scalar(&self.eval_operand(cond, None)?)?.to_bool()?;
|
let cond_val = self.read_scalar(&self.eval_operand(cond, None)?)?.to_bool()?;
|
||||||
if *expected == cond_val {
|
if expected == cond_val {
|
||||||
self.go_to_block(*target);
|
self.go_to_block(target);
|
||||||
} else {
|
} else {
|
||||||
M::assert_panic(self, msg, *cleanup)?;
|
M::assert_panic(self, msg, cleanup)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Abort => {
|
Abort => {
|
||||||
M::abort(self, "the program aborted execution".to_owned())?;
|
M::abort(self, "the program aborted execution".to_owned())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When we encounter Resume, we've finished unwinding
|
// When we encounter Resume, we've finished unwinding
|
||||||
// cleanup for the current stack frame. We pop it in order
|
// cleanup for the current stack frame. We pop it in order
|
||||||
// to continue unwinding the next frame
|
// to continue unwinding the next frame
|
||||||
@ -151,10 +154,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||||||
self.pop_stack_frame(/* unwinding */ true)?;
|
self.pop_stack_frame(/* unwinding */ true)?;
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// It is UB to ever encounter this.
|
// It is UB to ever encounter this.
|
||||||
Unreachable => throw_ub!(Unreachable),
|
Unreachable => throw_ub!(Unreachable),
|
||||||
|
|
||||||
// These should never occur for MIR we actually run.
|
// These should never occur for MIR we actually run.
|
||||||
DropAndReplace { .. }
|
DropAndReplace { .. }
|
||||||
| FalseEdge { .. }
|
| FalseEdge { .. }
|
||||||
@ -166,8 +167,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||||||
terminator.kind
|
terminator.kind
|
||||||
),
|
),
|
||||||
|
|
||||||
InlineAsm { template, operands, options, destination, .. } => {
|
InlineAsm { template, ref operands, options, destination, .. } => {
|
||||||
M::eval_inline_asm(self, template, operands, *options)?;
|
M::eval_inline_asm(self, template, operands, options)?;
|
||||||
if options.contains(InlineAsmOptions::NORETURN) {
|
if options.contains(InlineAsmOptions::NORETURN) {
|
||||||
throw_ub_format!("returned from noreturn inline assembly");
|
throw_ub_format!("returned from noreturn inline assembly");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user