Skip to content

Commit ab836ca

Browse files
committed
Fix transmuting fat pointers to integers
Fixes #1325
1 parent ece98a4 commit ab836ca

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

example/std_example.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,25 @@ fn main() {
155155
}
156156

157157
foo(I64X2(0, 0));
158+
159+
transmute_fat_pointer();
158160
}
159161

160162
fn panic(_: u128) {
161163
panic!();
162164
}
163165

166+
use std::mem::transmute;
167+
168+
#[cfg(target_pointer_width = "32")]
169+
type TwoPtrs = i64;
170+
#[cfg(target_pointer_width = "64")]
171+
type TwoPtrs = i128;
172+
173+
fn transmute_fat_pointer() -> TwoPtrs {
174+
unsafe { transmute::<_, TwoPtrs>("true !") }
175+
}
176+
164177
#[repr(simd)]
165178
struct I64X2(i64, i64);
166179

src/value_and_place.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,14 @@ impl<'tcx> CPlace<'tcx> {
587587
let dst_layout = self.layout();
588588
match self.inner {
589589
CPlaceInner::Var(_local, var) => {
590-
let data = CValue(from.0, dst_layout).load_scalar(fx);
590+
let data = match from.1.abi {
591+
Abi::Scalar(_) => CValue(from.0, dst_layout).load_scalar(fx),
592+
_ => {
593+
let (ptr, meta) = from.force_stack(fx);
594+
assert!(meta.is_none());
595+
CValue(CValueInner::ByRef(ptr, None), dst_layout).load_scalar(fx)
596+
}
597+
};
591598
let dst_ty = fx.clif_type(self.layout().ty).unwrap();
592599
transmute_scalar(fx, var, data, dst_ty);
593600
}

0 commit comments

Comments
 (0)