Fix transmuting fat pointers to integers

Fixes #1325
This commit is contained in:
bjorn3 2023-06-19 20:55:55 +00:00
parent ece98a4b41
commit ab836ca5e3
2 changed files with 21 additions and 1 deletions

View File

@ -155,12 +155,25 @@ fn main() {
}
foo(I64X2(0, 0));
transmute_fat_pointer();
}
fn panic(_: u128) {
panic!();
}
use std::mem::transmute;
#[cfg(target_pointer_width = "32")]
type TwoPtrs = i64;
#[cfg(target_pointer_width = "64")]
type TwoPtrs = i128;
fn transmute_fat_pointer() -> TwoPtrs {
unsafe { transmute::<_, TwoPtrs>("true !") }
}
#[repr(simd)]
struct I64X2(i64, i64);

View File

@ -587,7 +587,14 @@ impl<'tcx> CPlace<'tcx> {
let dst_layout = self.layout();
match self.inner {
CPlaceInner::Var(_local, var) => {
let data = CValue(from.0, dst_layout).load_scalar(fx);
let data = match from.1.abi {
Abi::Scalar(_) => CValue(from.0, dst_layout).load_scalar(fx),
_ => {
let (ptr, meta) = from.force_stack(fx);
assert!(meta.is_none());
CValue(CValueInner::ByRef(ptr, None), dst_layout).load_scalar(fx)
}
};
let dst_ty = fx.clif_type(self.layout().ty).unwrap();
transmute_scalar(fx, var, data, dst_ty);
}