Fix cranelift build
This commit is contained in:
parent
c478574786
commit
3a7970848c
@ -499,7 +499,7 @@ fn codegen_stmt<'tcx>(
|
||||
UnOp::Neg => match layout.ty.kind() {
|
||||
ty::Int(IntTy::I128) => {
|
||||
// FIXME remove this case once ineg.i128 works
|
||||
let zero = CValue::const_val(fx, layout, 0);
|
||||
let zero = CValue::const_val(fx, layout, ty::ScalarInt::null(layout.size));
|
||||
crate::num::codegen_int_binop(fx, BinOp::Sub, zero, operand)
|
||||
}
|
||||
ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
|
||||
@ -592,6 +592,7 @@ fn codegen_stmt<'tcx>(
|
||||
} else {
|
||||
discr.val
|
||||
};
|
||||
let discr = discr.into();
|
||||
|
||||
let discr = CValue::const_val(fx, fx.layout_of(to_ty), discr);
|
||||
lval.write_cvalue(fx, discr);
|
||||
|
@ -186,9 +186,8 @@ pub(crate) fn codegen_const_value<'tcx>(
|
||||
}
|
||||
|
||||
match x {
|
||||
Scalar::Raw { data, size } => {
|
||||
assert_eq!(u64::from(size), layout.size.bytes());
|
||||
CValue::const_val(fx, layout, data)
|
||||
Scalar::Raw(int) => {
|
||||
CValue::const_val(fx, layout, int)
|
||||
}
|
||||
Scalar::Ptr(ptr) => {
|
||||
let alloc_kind = fx.tcx.get_global_alloc(ptr.alloc_id);
|
||||
|
@ -30,7 +30,8 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
|
||||
.ty
|
||||
.discriminant_for_variant(fx.tcx, variant_index)
|
||||
.unwrap()
|
||||
.val;
|
||||
.val
|
||||
.into();
|
||||
let discr = CValue::const_val(fx, ptr.layout(), to);
|
||||
ptr.write_cvalue(fx, discr);
|
||||
}
|
||||
@ -49,7 +50,7 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
|
||||
let niche = place.place_field(fx, mir::Field::new(tag_field));
|
||||
let niche_value = variant_index.as_u32() - niche_variants.start().as_u32();
|
||||
let niche_value = u128::from(niche_value).wrapping_add(niche_start);
|
||||
let niche_llval = CValue::const_val(fx, niche.layout(), niche_value);
|
||||
let niche_llval = CValue::const_val(fx, niche.layout(), niche_value.into());
|
||||
niche.write_cvalue(fx, niche_llval);
|
||||
}
|
||||
}
|
||||
@ -77,7 +78,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
|
||||
.ty
|
||||
.discriminant_for_variant(fx.tcx, *index)
|
||||
.map_or(u128::from(index.as_u32()), |discr| discr.val);
|
||||
return CValue::const_val(fx, dest_layout, discr_val);
|
||||
return CValue::const_val(fx, dest_layout, discr_val.into());
|
||||
}
|
||||
Variants::Multiple {
|
||||
tag,
|
||||
|
@ -1064,7 +1064,8 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
|
||||
|
||||
fx.bcx.ins().call_indirect(f_sig, f, &[data]);
|
||||
|
||||
let ret_val = CValue::const_val(fx, ret.layout(), 0);
|
||||
let layout = ret.layout();
|
||||
let ret_val = CValue::const_val(fx, layout, ty::ScalarInt::null(layout.size));
|
||||
ret.write_cvalue(fx, ret_val);
|
||||
};
|
||||
|
||||
|
@ -231,15 +231,16 @@ impl<'tcx> CValue<'tcx> {
|
||||
pub(crate) fn const_val(
|
||||
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
const_val: u128,
|
||||
const_val: ty::ScalarInt,
|
||||
) -> CValue<'tcx> {
|
||||
assert_eq!(const_val.size(), layout.size);
|
||||
use cranelift_codegen::ir::immediates::{Ieee32, Ieee64};
|
||||
|
||||
let clif_ty = fx.clif_type(layout.ty).unwrap();
|
||||
|
||||
if let ty::Bool = layout.ty.kind() {
|
||||
assert!(
|
||||
const_val == 0 || const_val == 1,
|
||||
const_val == ty::ScalarInt::FALSE || const_val == ty::ScalarInt::TRUE,
|
||||
"Invalid bool 0x{:032X}",
|
||||
const_val
|
||||
);
|
||||
@ -247,6 +248,7 @@ impl<'tcx> CValue<'tcx> {
|
||||
|
||||
let val = match layout.ty.kind() {
|
||||
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
|
||||
let const_val = const_val.to_bits(layout.size).unwrap();
|
||||
let lsb = fx.bcx.ins().iconst(types::I64, const_val as u64 as i64);
|
||||
let msb = fx
|
||||
.bcx
|
||||
|
@ -353,3 +353,17 @@ impl fmt::LowerHex for ScalarInt {
|
||||
write!(f, "{:01$x}", { self.data }, self.size as usize * 2)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::UpperHex for ScalarInt {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.check_data();
|
||||
// Format as hex number wide enough to fit any value of the given `size`.
|
||||
// So data=20, size=1 will be "0x14", but with size=4 it'll be "0x00000014".
|
||||
// Using a block `{self.data}` here to force a copy instead of using `self.data`
|
||||
// directly, because `write!` takes references to its formatting arguments and
|
||||
// would thus borrow `self.data`. Since `Self`
|
||||
// is a packed struct, that would create a possibly unaligned reference, which
|
||||
// is UB on a lot of platforms.
|
||||
write!(f, "{:01$X}", { self.data }, self.size as usize * 2)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user