Fix transmutes between vectors and integers

Fixes #1102
This commit is contained in:
bjorn3 2020-11-01 18:35:19 +01:00
parent c674c2c46c
commit 8b9c2135d0

View File

@ -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