Split a bool argument into two named functions
This commit is contained in:
parent
ca109af2ac
commit
fc9d1a8133
12 changed files with 39 additions and 30 deletions
|
@ -153,7 +153,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.copy_op(src, dest, /*allow_transmute*/ true)?;
|
self.copy_op_allow_transmute(src, dest)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -441,7 +441,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
if src_field.layout.is_1zst() && cast_ty_field.is_1zst() {
|
if src_field.layout.is_1zst() && cast_ty_field.is_1zst() {
|
||||||
// Skip 1-ZST fields.
|
// Skip 1-ZST fields.
|
||||||
} else if src_field.layout.ty == cast_ty_field.ty {
|
} else if src_field.layout.ty == cast_ty_field.ty {
|
||||||
self.copy_op(&src_field, &dst_field, /*allow_transmute*/ false)?;
|
self.copy_op(&src_field, &dst_field)?;
|
||||||
} else {
|
} else {
|
||||||
if found_cast_field {
|
if found_cast_field {
|
||||||
span_bug!(self.cur_span(), "unsize_into: more than one field to cast");
|
span_bug!(self.cur_span(), "unsize_into: more than one field to cast");
|
||||||
|
|
|
@ -899,7 +899,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
.local_to_op(self.frame(), mir::RETURN_PLACE, None)
|
.local_to_op(self.frame(), mir::RETURN_PLACE, None)
|
||||||
.expect("return place should always be live");
|
.expect("return place should always be live");
|
||||||
let dest = self.frame().return_place.clone();
|
let dest = self.frame().return_place.clone();
|
||||||
let err = self.copy_op(&op, &dest, /*allow_transmute*/ true);
|
let err = self.copy_op_allow_transmute(&op, &dest);
|
||||||
trace!("return value: {:?}", self.dump_place(&dest));
|
trace!("return value: {:?}", self.dump_place(&dest));
|
||||||
// We delay actually short-circuiting on this error until *after* the stack frame is
|
// We delay actually short-circuiting on this error until *after* the stack frame is
|
||||||
// popped, since we want this error to be attributed to the caller, whose type defines
|
// popped, since we want this error to be attributed to the caller, whose type defines
|
||||||
|
|
|
@ -120,7 +120,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
let val = self.tcx.span_as_caller_location(span);
|
let val = self.tcx.span_as_caller_location(span);
|
||||||
let val =
|
let val =
|
||||||
self.const_val_to_op(val, self.tcx.caller_location_ty(), Some(dest.layout))?;
|
self.const_val_to_op(val, self.tcx.caller_location_ty(), Some(dest.layout))?;
|
||||||
self.copy_op(&val, dest, /* allow_transmute */ false)?;
|
self.copy_op(&val, dest)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
sym::min_align_of_val | sym::size_of_val => {
|
sym::min_align_of_val | sym::size_of_val => {
|
||||||
|
@ -157,7 +157,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
tcx.const_eval_global_id(self.param_env, gid, Some(tcx.span))
|
tcx.const_eval_global_id(self.param_env, gid, Some(tcx.span))
|
||||||
})?;
|
})?;
|
||||||
let val = self.const_val_to_op(val, ty, Some(dest.layout))?;
|
let val = self.const_val_to_op(val, ty, Some(dest.layout))?;
|
||||||
self.copy_op(&val, dest, /*allow_transmute*/ false)?;
|
self.copy_op(&val, dest)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
sym::ctpop
|
sym::ctpop
|
||||||
|
@ -391,7 +391,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
} else {
|
} else {
|
||||||
self.project_index(&input, i)?.into()
|
self.project_index(&input, i)?.into()
|
||||||
};
|
};
|
||||||
self.copy_op(&value, &place, /*allow_transmute*/ false)?;
|
self.copy_op(&value, &place)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sym::simd_extract => {
|
sym::simd_extract => {
|
||||||
|
@ -401,15 +401,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
index < input_len,
|
index < input_len,
|
||||||
"index `{index}` must be in bounds of vector with length {input_len}"
|
"index `{index}` must be in bounds of vector with length {input_len}"
|
||||||
);
|
);
|
||||||
self.copy_op(
|
self.copy_op(&self.project_index(&input, index)?, dest)?;
|
||||||
&self.project_index(&input, index)?,
|
|
||||||
dest,
|
|
||||||
/*allow_transmute*/ false,
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
sym::likely | sym::unlikely | sym::black_box => {
|
sym::likely | sym::unlikely | sym::black_box => {
|
||||||
// These just return their argument
|
// These just return their argument
|
||||||
self.copy_op(&args[0], dest, /*allow_transmute*/ false)?;
|
self.copy_op(&args[0], dest)?;
|
||||||
}
|
}
|
||||||
sym::raw_eq => {
|
sym::raw_eq => {
|
||||||
let result = self.raw_eq_intrinsic(&args[0], &args[1])?;
|
let result = self.raw_eq_intrinsic(&args[0], &args[1])?;
|
||||||
|
|
|
@ -758,11 +758,32 @@ where
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Copies the data from an operand to a place.
|
||||||
|
/// The layouts of the `src` and `dest` may disagree.
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn copy_op_allow_transmute(
|
||||||
|
&mut self,
|
||||||
|
src: &impl Readable<'tcx, M::Provenance>,
|
||||||
|
dest: &impl Writeable<'tcx, M::Provenance>,
|
||||||
|
) -> InterpResult<'tcx> {
|
||||||
|
self.copy_op_inner(src, dest, /* allow_transmute */ true)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Copies the data from an operand to a place.
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn copy_op(
|
||||||
|
&mut self,
|
||||||
|
src: &impl Readable<'tcx, M::Provenance>,
|
||||||
|
dest: &impl Writeable<'tcx, M::Provenance>,
|
||||||
|
) -> InterpResult<'tcx> {
|
||||||
|
self.copy_op_inner(src, dest, /* allow_transmute */ false)
|
||||||
|
}
|
||||||
|
|
||||||
/// Copies the data from an operand to a place.
|
/// Copies the data from an operand to a place.
|
||||||
/// `allow_transmute` indicates whether the layouts may disagree.
|
/// `allow_transmute` indicates whether the layouts may disagree.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
#[instrument(skip(self), level = "debug")]
|
#[instrument(skip(self), level = "debug")]
|
||||||
pub fn copy_op(
|
fn copy_op_inner(
|
||||||
&mut self,
|
&mut self,
|
||||||
src: &impl Readable<'tcx, M::Provenance>,
|
src: &impl Readable<'tcx, M::Provenance>,
|
||||||
dest: &impl Writeable<'tcx, M::Provenance>,
|
dest: &impl Writeable<'tcx, M::Provenance>,
|
||||||
|
|
|
@ -151,12 +151,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
Use(ref operand) => {
|
Use(ref operand) => {
|
||||||
// Avoid recomputing the layout
|
// Avoid recomputing the layout
|
||||||
let op = self.eval_operand(operand, Some(dest.layout))?;
|
let op = self.eval_operand(operand, Some(dest.layout))?;
|
||||||
self.copy_op(&op, &dest, /*allow_transmute*/ false)?;
|
self.copy_op(&op, &dest)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
CopyForDeref(place) => {
|
CopyForDeref(place) => {
|
||||||
let op = self.eval_place_to_op(place, Some(dest.layout))?;
|
let op = self.eval_place_to_op(place, Some(dest.layout))?;
|
||||||
self.copy_op(&op, &dest, /* allow_transmute*/ false)?;
|
self.copy_op(&op, &dest)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
BinaryOp(bin_op, box (ref left, ref right)) => {
|
BinaryOp(bin_op, box (ref left, ref right)) => {
|
||||||
|
@ -316,7 +316,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
let field_index = active_field_index.unwrap_or(field_index);
|
let field_index = active_field_index.unwrap_or(field_index);
|
||||||
let field_dest = self.project_field(&variant_dest, field_index.as_usize())?;
|
let field_dest = self.project_field(&variant_dest, field_index.as_usize())?;
|
||||||
let op = self.eval_operand(operand, Some(field_dest.layout))?;
|
let op = self.eval_operand(operand, Some(field_dest.layout))?;
|
||||||
self.copy_op(&op, &field_dest, /*allow_transmute*/ false)?;
|
self.copy_op(&op, &field_dest)?;
|
||||||
}
|
}
|
||||||
self.write_discriminant(variant_index, dest)
|
self.write_discriminant(variant_index, dest)
|
||||||
}
|
}
|
||||||
|
@ -339,7 +339,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
} else {
|
} else {
|
||||||
// Write the src to the first element.
|
// Write the src to the first element.
|
||||||
let first = self.project_index(&dest, 0)?;
|
let first = self.project_index(&dest, 0)?;
|
||||||
self.copy_op(&src, &first, /*allow_transmute*/ false)?;
|
self.copy_op(&src, &first)?;
|
||||||
|
|
||||||
// This is performance-sensitive code for big static/const arrays! So we
|
// This is performance-sensitive code for big static/const arrays! So we
|
||||||
// avoid writing each operand individually and instead just make many copies
|
// avoid writing each operand individually and instead just make many copies
|
||||||
|
|
|
@ -481,7 +481,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
// FIXME: Depending on the PassMode, this should reset some padding to uninitialized. (This
|
// FIXME: Depending on the PassMode, this should reset some padding to uninitialized. (This
|
||||||
// is true for all `copy_op`, but there are a lot of special cases for argument passing
|
// is true for all `copy_op`, but there are a lot of special cases for argument passing
|
||||||
// specifically.)
|
// specifically.)
|
||||||
self.copy_op(&caller_arg_copy, &callee_arg, /*allow_transmute*/ true)?;
|
self.copy_op_allow_transmute(&caller_arg_copy, &callee_arg)?;
|
||||||
// If this was an in-place pass, protect the place it comes from for the duration of the call.
|
// If this was an in-place pass, protect the place it comes from for the duration of the call.
|
||||||
if let FnArg::InPlace(place) = caller_arg {
|
if let FnArg::InPlace(place) = caller_arg {
|
||||||
M::protect_in_place_function_argument(self, place)?;
|
M::protect_in_place_function_argument(self, place)?;
|
||||||
|
|
|
@ -399,7 +399,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
|
||||||
};
|
};
|
||||||
for (field_index, op) in fields.into_iter().enumerate() {
|
for (field_index, op) in fields.into_iter().enumerate() {
|
||||||
let field_dest = self.ecx.project_field(&variant_dest, field_index).ok()?;
|
let field_dest = self.ecx.project_field(&variant_dest, field_index).ok()?;
|
||||||
self.ecx.copy_op(op, &field_dest, /*allow_transmute*/ false).ok()?;
|
self.ecx.copy_op(op, &field_dest).ok()?;
|
||||||
}
|
}
|
||||||
self.ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), &dest).ok()?;
|
self.ecx.write_discriminant(variant.unwrap_or(FIRST_VARIANT), &dest).ok()?;
|
||||||
self.ecx
|
self.ecx
|
||||||
|
@ -1181,8 +1181,7 @@ fn op_to_prop_const<'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Everything failed: create a new allocation to hold the data.
|
// Everything failed: create a new allocation to hold the data.
|
||||||
let alloc_id =
|
let alloc_id = ecx.intern_with_temp_alloc(op.layout, |ecx, dest| ecx.copy_op(op, dest)).ok()?;
|
||||||
ecx.intern_with_temp_alloc(op.layout, |ecx, dest| ecx.copy_op(op, dest, false)).ok()?;
|
|
||||||
let value = ConstValue::Indirect { alloc_id, offset: Size::ZERO };
|
let value = ConstValue::Indirect { alloc_id, offset: Size::ZERO };
|
||||||
|
|
||||||
// Check that we do not leak a pointer.
|
// Check that we do not leak a pointer.
|
||||||
|
|
|
@ -108,12 +108,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
|
||||||
"volatile_load" => {
|
"volatile_load" => {
|
||||||
let [place] = check_arg_count(args)?;
|
let [place] = check_arg_count(args)?;
|
||||||
let place = this.deref_pointer(place)?;
|
let place = this.deref_pointer(place)?;
|
||||||
this.copy_op(&place, dest, /*allow_transmute*/ false)?;
|
this.copy_op(&place, dest)?;
|
||||||
}
|
}
|
||||||
"volatile_store" => {
|
"volatile_store" => {
|
||||||
let [place, dest] = check_arg_count(args)?;
|
let [place, dest] = check_arg_count(args)?;
|
||||||
let place = this.deref_pointer(place)?;
|
let place = this.deref_pointer(place)?;
|
||||||
this.copy_op(dest, &place, /*allow_transmute*/ false)?;
|
this.copy_op(dest, &place)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
"write_bytes" | "volatile_set_memory" => {
|
"write_bytes" | "volatile_set_memory" => {
|
||||||
|
|
|
@ -299,7 +299,6 @@ fn bin_op_simd_float_first<'tcx, F: rustc_apfloat::Float>(
|
||||||
this.copy_op(
|
this.copy_op(
|
||||||
&this.project_index(&left, i)?,
|
&this.project_index(&left, i)?,
|
||||||
&this.project_index(&dest, i)?,
|
&this.project_index(&dest, i)?,
|
||||||
/*allow_transmute*/ false,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,7 +423,6 @@ fn unary_op_ss<'tcx>(
|
||||||
this.copy_op(
|
this.copy_op(
|
||||||
&this.project_index(&op, i)?,
|
&this.project_index(&op, i)?,
|
||||||
&this.project_index(&dest, i)?,
|
&this.project_index(&dest, i)?,
|
||||||
/*allow_transmute*/ false,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,7 +482,6 @@ fn round_first<'tcx, F: rustc_apfloat::Float>(
|
||||||
this.copy_op(
|
this.copy_op(
|
||||||
&this.project_index(&left, i)?,
|
&this.project_index(&left, i)?,
|
||||||
&this.project_index(&dest, i)?,
|
&this.project_index(&dest, i)?,
|
||||||
/*allow_transmute*/ false,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -211,7 +211,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
|
||||||
this.copy_op(
|
this.copy_op(
|
||||||
&this.project_index(&left, i)?,
|
&this.project_index(&left, i)?,
|
||||||
&this.project_index(&dest, i)?,
|
&this.project_index(&dest, i)?,
|
||||||
/*allow_transmute*/ false,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -443,7 +443,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
|
||||||
this.copy_op(
|
this.copy_op(
|
||||||
&this.project_index(&op, i)?,
|
&this.project_index(&op, i)?,
|
||||||
&this.project_index(&dest, i)?,
|
&this.project_index(&dest, i)?,
|
||||||
/*allow_transmute*/ false,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -584,7 +583,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
|
||||||
this.copy_op(
|
this.copy_op(
|
||||||
&this.project_index(&left, i)?,
|
&this.project_index(&left, i)?,
|
||||||
&this.project_index(&dest, i)?,
|
&this.project_index(&dest, i)?,
|
||||||
/*allow_transmute*/ false,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,6 @@ pub(super) trait EvalContextExt<'mir, 'tcx: 'mir>:
|
||||||
this.copy_op(
|
this.copy_op(
|
||||||
&this.project_index(&left, i)?,
|
&this.project_index(&left, i)?,
|
||||||
&dest,
|
&dest,
|
||||||
/*allow_transmute*/ false,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue