Skip to content

Commit

Permalink
fix issue 184 by marking the destination as a packed struct
Browse files Browse the repository at this point in the history
  • Loading branch information
David Renshaw committed Jun 6, 2017
1 parent 58a4639 commit c8be312
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/terminator/intrinsic.rs
Expand Up @@ -383,8 +383,17 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
}

"transmute" => {
let src_ty = substs.type_at(0);
let dest_ty = substs.type_at(1);
self.write_value(arg_vals[0], dest, dest_ty)?;
let (_, src_align) = self.size_and_align_of_dst(src_ty, arg_vals[0])?;
let (size, dest_align) = self.size_and_align_of_dst(dest_ty, arg_vals[0])?;
if dest_align < src_align {
let ptr = self.force_allocation(dest)?.to_ptr();
self.memory.mark_packed(ptr, size);
self.write_value_to_ptr(arg_vals[0], ptr, dest_ty)?;
} else {
self.write_value(arg_vals[0], dest, dest_ty)?;
}
}

"uninit" => {
Expand Down
4 changes: 4 additions & 0 deletions tests/run-pass/issue-miri-184.rs
@@ -0,0 +1,4 @@
pub fn main() {
let bytes: [u8; 8] = unsafe { ::std::mem::transmute(0u64) };
let _: &[u8] = &bytes;
}

0 comments on commit c8be312

Please sign in to comment.