Skip to content

Commit 8b9c213

Browse files
committed
Fix transmutes between vectors and integers
Fixes rust-lang#1102
1 parent c674c2c commit 8b9c213

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/value_and_place.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl<'tcx> CPlace<'tcx> {
332332

333333
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
334334
kind: StackSlotKind::ExplicitSlot,
335-
size: layout.size.bytes() as u32,
335+
size: u32::try_from(layout.size.bytes()).unwrap(),
336336
offset: None,
337337
});
338338
CPlace {
@@ -530,6 +530,13 @@ impl<'tcx> CPlace<'tcx> {
530530
dst_ty: Type,
531531
) {
532532
let src_ty = fx.bcx.func.dfg.value_type(data);
533+
assert_eq!(
534+
src_ty.bytes(),
535+
dst_ty.bytes(),
536+
"write_cvalue_transmute: {:?} -> {:?}",
537+
src_ty,
538+
dst_ty,
539+
);
533540
let data = match (src_ty, dst_ty) {
534541
(_, _) if src_ty == dst_ty => data,
535542

@@ -541,6 +548,17 @@ impl<'tcx> CPlace<'tcx> {
541548
_ if src_ty.is_vector() && dst_ty.is_vector() => {
542549
fx.bcx.ins().raw_bitcast(dst_ty, data)
543550
}
551+
_ if src_ty.is_vector() || dst_ty.is_vector() => {
552+
// FIXME do something more efficient for transmutes between vectors and integers.
553+
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {
554+
kind: StackSlotKind::ExplicitSlot,
555+
size: src_ty.bytes(),
556+
offset: None,
557+
});
558+
let ptr = Pointer::stack_slot(stack_slot);
559+
ptr.store(fx, data, MemFlags::trusted());
560+
ptr.load(fx, dst_ty, MemFlags::trusted())
561+
}
544562
_ => unreachable!("write_cvalue_transmute: {:?} -> {:?}", src_ty, dst_ty),
545563
};
546564
fx.bcx

0 commit comments

Comments
 (0)