+
+ if layout.is_zst() {
+ return CValue::by_ref(
+ crate::Pointer::const_addr(fx, i64::try_from(layout.align.pref.bytes()).unwrap()),
+ layout,
+ );
+ }
+
+ let const_val = match const_.val {
+ ConstKind::Value(const_val) => const_val,
+ _ => unreachable!("Const {:?} should have been evaluated", const_),
+ };
+
+ match const_val {
+ ConstValue::Scalar(x) => {
+ let scalar = match layout.abi {
+ layout::Abi::Scalar(ref x) => x,
+ _ => bug!("from_const: invalid ByVal layout: {:#?}", layout),
+ };
+
+ match ty.kind {
+ ty::Bool | ty::Uint(_) => {
+ let bits = const_.val.try_to_bits(layout.size).unwrap_or_else(|| {
+ panic!("{:?}\n{:?}", const_, layout);
+ });
+ CValue::const_val(fx, ty, bits)
+ }
+ ty::Int(_) => {
+ let bits = const_.val.try_to_bits(layout.size).unwrap();
+ CValue::const_val(
+ fx,
+ ty,
+ rustc::mir::interpret::sign_extend(bits, layout.size),
+ )
+ }
+ ty::Float(fty) => {
+ let bits = const_.val.try_to_bits(layout.size).unwrap();
+ let val = match fty {
+ FloatTy::F32 => fx
+ .bcx
+ .ins()
+ .f32const(Ieee32::with_bits(u32::try_from(bits).unwrap())),
+ FloatTy::F64 => fx
+ .bcx
+ .ins()
+ .f64const(Ieee64::with_bits(u64::try_from(bits).unwrap())),
+ };
+ CValue::by_val(val, layout)
+ }
+ ty::FnDef(_def_id, _substs) => CValue::by_ref(
+ crate::pointer::Pointer::const_addr(fx, fx.pointer_type.bytes() as i64),
+ layout,
+ ),
+ _ => trans_const_place(fx, const_).to_cvalue(fx),
+ }