Skip to content

Commit 7e8b15e

Browse files
committed
Fix cranelift build
1 parent 285c7c6 commit 7e8b15e

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

src/base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ fn codegen_stmt<'tcx>(
499499
UnOp::Neg => match layout.ty.kind() {
500500
ty::Int(IntTy::I128) => {
501501
// FIXME remove this case once ineg.i128 works
502-
let zero = CValue::const_val(fx, layout, 0);
502+
let zero = CValue::const_val(fx, layout, ty::ScalarInt::null(layout.size));
503503
crate::num::codegen_int_binop(fx, BinOp::Sub, zero, operand)
504504
}
505505
ty::Int(_) => CValue::by_val(fx.bcx.ins().ineg(val), layout),
@@ -592,6 +592,7 @@ fn codegen_stmt<'tcx>(
592592
} else {
593593
discr.val
594594
};
595+
let discr = discr.into();
595596

596597
let discr = CValue::const_val(fx, fx.layout_of(to_ty), discr);
597598
lval.write_cvalue(fx, discr);

src/constant.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,8 @@ pub(crate) fn codegen_const_value<'tcx>(
186186
}
187187

188188
match x {
189-
Scalar::Raw { data, size } => {
190-
assert_eq!(u64::from(size), layout.size.bytes());
191-
CValue::const_val(fx, layout, data)
189+
Scalar::Raw(int) => {
190+
CValue::const_val(fx, layout, int)
192191
}
193192
Scalar::Ptr(ptr) => {
194193
let alloc_kind = fx.tcx.get_global_alloc(ptr.alloc_id);

src/discriminant.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
3030
.ty
3131
.discriminant_for_variant(fx.tcx, variant_index)
3232
.unwrap()
33-
.val;
33+
.val
34+
.into();
3435
let discr = CValue::const_val(fx, ptr.layout(), to);
3536
ptr.write_cvalue(fx, discr);
3637
}
@@ -49,7 +50,7 @@ pub(crate) fn codegen_set_discriminant<'tcx>(
4950
let niche = place.place_field(fx, mir::Field::new(tag_field));
5051
let niche_value = variant_index.as_u32() - niche_variants.start().as_u32();
5152
let niche_value = u128::from(niche_value).wrapping_add(niche_start);
52-
let niche_llval = CValue::const_val(fx, niche.layout(), niche_value);
53+
let niche_llval = CValue::const_val(fx, niche.layout(), niche_value.into());
5354
niche.write_cvalue(fx, niche_llval);
5455
}
5556
}
@@ -77,7 +78,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>(
7778
.ty
7879
.discriminant_for_variant(fx.tcx, *index)
7980
.map_or(u128::from(index.as_u32()), |discr| discr.val);
80-
return CValue::const_val(fx, dest_layout, discr_val);
81+
return CValue::const_val(fx, dest_layout, discr_val.into());
8182
}
8283
Variants::Multiple {
8384
tag,

src/intrinsics/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,8 @@ pub(crate) fn codegen_intrinsic_call<'tcx>(
10641064

10651065
fx.bcx.ins().call_indirect(f_sig, f, &[data]);
10661066

1067-
let ret_val = CValue::const_val(fx, ret.layout(), 0);
1067+
let layout = ret.layout();
1068+
let ret_val = CValue::const_val(fx, layout, ty::ScalarInt::null(layout.size));
10681069
ret.write_cvalue(fx, ret_val);
10691070
};
10701071

src/value_and_place.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,24 @@ impl<'tcx> CValue<'tcx> {
231231
pub(crate) fn const_val(
232232
fx: &mut FunctionCx<'_, 'tcx, impl Module>,
233233
layout: TyAndLayout<'tcx>,
234-
const_val: u128,
234+
const_val: ty::ScalarInt,
235235
) -> CValue<'tcx> {
236+
assert_eq!(const_val.size(), layout.size);
236237
use cranelift_codegen::ir::immediates::{Ieee32, Ieee64};
237238

238239
let clif_ty = fx.clif_type(layout.ty).unwrap();
239240

240241
if let ty::Bool = layout.ty.kind() {
241242
assert!(
242-
const_val == 0 || const_val == 1,
243+
const_val == ty::ScalarInt::FALSE || const_val == ty::ScalarInt::TRUE,
243244
"Invalid bool 0x{:032X}",
244245
const_val
245246
);
246247
}
247248

248249
let val = match layout.ty.kind() {
249250
ty::Uint(UintTy::U128) | ty::Int(IntTy::I128) => {
251+
let const_val = const_val.to_bits(layout.size).unwrap();
250252
let lsb = fx.bcx.ins().iconst(types::I64, const_val as u64 as i64);
251253
let msb = fx
252254
.bcx

0 commit comments

Comments
 (0)