From e1ac09a3f042c0afec8ed3398e9b3b3912fc75ea Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 9 Aug 2018 15:44:01 +0200 Subject: [PATCH] Implement bool -> int cast --- src/base.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/base.rs b/src/base.rs index 4bc3455965d..6e7d1574fff 100644 --- a/src/base.rs +++ b/src/base.rs @@ -429,6 +429,17 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, cur_ebb: Ebb, stmt: & let res = fx.bcx.ins().fcvt_from_uint(f_type, from); lval.write_cvalue(fx, CValue::ByVal(res, dest_layout)); } + (TypeVariants::TyBool, TypeVariants::TyUint(_)) + | (TypeVariants::TyBool, TypeVariants::TyInt(_)) => { + let to_ty = fx.cton_type(to_ty).unwrap(); + let from = operand.load_value(fx); + let res = if to_ty != types::I8 { + fx.bcx.ins().uextend(to_ty, from) + } else { + from + }; + lval.write_cvalue(fx, CValue::ByVal(res, dest_layout)); + } _ => unimpl!("rval misc {:?} {:?}", from_ty, to_ty), } }