diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2020-11-01 18:35:19 +0100 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2020-11-01 18:35:19 +0100 |
| commit | 8b9c2135d06ee0255d24b18efba8ef9cf92fb67f (patch) | |
| tree | f14d36ffdbd0fd6ffadccfed9a31590401bc0f8a | |
| parent | c674c2c46c140e0e260dfe140ac941d3088e7139 (diff) | |
| download | rust-8b9c2135d06ee0255d24b18efba8ef9cf92fb67f.tar.gz rust-8b9c2135d06ee0255d24b18efba8ef9cf92fb67f.zip | |
Fix transmutes between vectors and integers
Fixes #1102
| -rw-r--r-- | src/value_and_place.rs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/value_and_place.rs b/src/value_and_place.rs index 9a2470ba40d..2b9ea5273b6 100644 --- a/src/value_and_place.rs +++ b/src/value_and_place.rs @@ -332,7 +332,7 @@ impl<'tcx> CPlace<'tcx> { let stack_slot = fx.bcx.create_stack_slot(StackSlotData { kind: StackSlotKind::ExplicitSlot, - size: layout.size.bytes() as u32, + size: u32::try_from(layout.size.bytes()).unwrap(), offset: None, }); CPlace { @@ -530,6 +530,13 @@ impl<'tcx> CPlace<'tcx> { dst_ty: Type, ) { let src_ty = fx.bcx.func.dfg.value_type(data); + assert_eq!( + src_ty.bytes(), + dst_ty.bytes(), + "write_cvalue_transmute: {:?} -> {:?}", + src_ty, + dst_ty, + ); let data = match (src_ty, dst_ty) { (_, _) if src_ty == dst_ty => data, @@ -541,6 +548,17 @@ impl<'tcx> CPlace<'tcx> { _ if src_ty.is_vector() && dst_ty.is_vector() => { fx.bcx.ins().raw_bitcast(dst_ty, data) } + _ if src_ty.is_vector() || dst_ty.is_vector() => { + // FIXME do something more efficient for transmutes between vectors and integers. + let stack_slot = fx.bcx.create_stack_slot(StackSlotData { + kind: StackSlotKind::ExplicitSlot, + size: src_ty.bytes(), + offset: None, + }); + let ptr = Pointer::stack_slot(stack_slot); + ptr.store(fx, data, MemFlags::trusted()); + ptr.load(fx, dst_ty, MemFlags::trusted()) + } _ => unreachable!("write_cvalue_transmute: {:?} -> {:?}", src_ty, dst_ty), }; fx.bcx |
