Skip to content

Commit ad009ae

Browse files
committed
fix using copy_op to transmute
1 parent 23d86b0 commit ad009ae

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/librustc_mir/interpret/place.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -520,22 +520,22 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
520520
trace!("write_value: {:?} <- {:?}", *dest, src_val);
521521
// See if we can avoid an allocation. This is the counterpart to `try_read_value`,
522522
// but not factored as a separate function.
523-
match dest.place {
523+
let mplace = match dest.place {
524524
Place::Local { frame, local } => {
525525
match *self.stack[frame].locals[local].access_mut()? {
526526
Operand::Immediate(ref mut dest_val) => {
527527
// Yay, we can just change the local directly.
528528
*dest_val = src_val;
529529
return Ok(());
530530
},
531-
_ => {},
531+
Operand::Indirect(mplace) => mplace, // already in memory
532532
}
533533
},
534-
_ => {},
534+
Place::Ptr(mplace) => mplace, // already in memory
535535
};
536536

537-
// Slow path: write to memory
538-
let dest = self.force_allocation(dest)?;
537+
// This is already in memory, write there.
538+
let dest = MPlaceTy { mplace, layout: dest.layout };
539539
self.write_value_to_mplace(src_val, dest)
540540
}
541541

@@ -565,7 +565,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
565565
Value::ScalarPair(a_val, b_val) => {
566566
let (a, b) = match dest.layout.abi {
567567
layout::Abi::ScalarPair(ref a, ref b) => (&a.value, &b.value),
568-
_ => bug!("write_value_to_ptr: invalid ScalarPair layout: {:#?}", dest.layout)
568+
_ => bug!("write_value_to_mplace: invalid ScalarPair layout: {:#?}", dest.layout)
569569
};
570570
let (a_size, b_size) = (a.size(&self), b.size(&self));
571571
let (a_align, b_align) = (a.align(&self), b.align(&self));
@@ -591,8 +591,10 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> {
591591
// Let us see if the layout is simple so we take a shortcut, avoid force_allocation.
592592
let (src_ptr, src_align) = match self.try_read_value(src)? {
593593
Ok(src_val) =>
594-
// Yay, we got a value that we can write directly.
595-
return self.write_value(src_val, dest),
594+
// Yay, we got a value that we can write directly. We write with the
595+
// *source layout*, because that was used to load, and if they do not match
596+
// this is a transmute we want to support.
597+
return self.write_value(src_val, PlaceTy { place: *dest, layout: src.layout }),
596598
Err(mplace) => mplace.to_scalar_ptr_align(),
597599
};
598600
// Slow path, this does not fit into an immediate. Just memcpy.

0 commit comments

Comments
 (0)