Skip to content

Commit 9b66df4

Browse files
committed
Sync from rust dc06a36
2 parents 66e4f1b + d6f457d commit 9b66df4

File tree

6 files changed

+18
-17
lines changed

6 files changed

+18
-17
lines changed

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2020-11-03
1+
nightly-2020-11-06

src/base.rs

Lines changed: 3 additions & 5 deletions
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),
@@ -585,13 +585,11 @@ fn codegen_stmt<'tcx>(
585585
.discriminant_for_variant(fx.tcx, *index)
586586
.unwrap();
587587
let discr = if discr.ty.is_signed() {
588-
rustc_middle::mir::interpret::sign_extend(
589-
discr.val,
590-
fx.layout_of(discr.ty).size,
591-
)
588+
fx.layout_of(discr.ty).size.sign_extend(discr.val)
592589
} else {
593590
discr.val
594591
};
592+
let discr = discr.into();
595593

596594
let discr = CValue::const_val(fx, fx.layout_of(to_ty), discr);
597595
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::Int(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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Handling of enum discriminants
22
//!
3-
//! Adapted from https://github.com/rust-lang/rust/blob/d760df5aea483aae041c9a241e7acacf48f75035/src/librustc_codegen_ssa/mir/place.rs
3+
//! Adapted from <https://github.com/rust-lang/rust/blob/d760df5aea483aae041c9a241e7acacf48f75035/src/librustc_codegen_ssa/mir/place.rs>
44
55
use rustc_target::abi::{Int, TagEncoding, Variants};
66

@@ -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: 5 additions & 3 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
@@ -259,7 +261,7 @@ impl<'tcx> CValue<'tcx> {
259261
fx
260262
.bcx
261263
.ins()
262-
.iconst(clif_ty, u64::try_from(const_val).expect("uint") as i64)
264+
.iconst(clif_ty, const_val.to_bits(layout.size).unwrap() as i64)
263265
}
264266
ty::Float(FloatTy::F32) => {
265267
fx.bcx.ins().f32const(Ieee32::with_bits(u32::try_from(const_val).unwrap()))

0 commit comments

Comments
 (0)