Merge pull request #187 from dwrensha/fix-issue-184-mark-packed

fix issue 184 by marking the destination as a packed struct
This commit is contained in:
Oliver Schneider 2017-06-06 17:47:04 +02:00 committed by GitHub
commit cad0188c72
2 changed files with 15 additions and 1 deletions

View File

@ -383,8 +383,18 @@ pub(super) fn call_intrinsic(
}
"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.type_align(src_ty)?;
let dest_align = self.type_align(dest_ty)?;
let size = self.type_size(dest_ty)?.expect("transmute() type must be sized");
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" => {

View File

@ -0,0 +1,4 @@
pub fn main() {
let bytes: [u8; 8] = unsafe { ::std::mem::transmute(0u64) };
let _: &[u8] = &bytes;
}