Workaround missing encoding for icmp.i8
This commit is contained in:
parent
3f4926f43f
commit
4b10e6e613
@ -33,7 +33,6 @@ $ ./build.sh
|
||||
## Not yet supported
|
||||
|
||||
* Checked binops
|
||||
* Statics
|
||||
* Drop glue
|
||||
|
||||
* Building libraries
|
||||
|
@ -27,7 +27,7 @@ fn start(_main: *const u8, i: isize, _: *const *const u8) -> isize {
|
||||
}
|
||||
|
||||
unsafe {
|
||||
NUM = 6 * 7 + 5;
|
||||
NUM = 6 * 7 + 1 + (1u8 == 1u8) as u8; // 44
|
||||
*NUM_REF as isize
|
||||
}
|
||||
}
|
||||
|
30
src/base.rs
30
src/base.rs
@ -382,13 +382,13 @@ fn trans_stmt<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, cur_ebb: Ebb, stmt: &
|
||||
| (TypeVariants::TyUint(_), TypeVariants::TyInt(_))
|
||||
| (TypeVariants::TyUint(_), TypeVariants::TyUint(_)) => {
|
||||
let from = operand.load_value(fx);
|
||||
let res = crate::common::cton_intcast(fx, from, from_ty, to_ty, false);
|
||||
let res = crate::common::cton_intcast(fx, from, fx.cton_type(to_ty).unwrap(), false);
|
||||
lval.write_cvalue(fx, CValue::ByVal(res, dest_layout));
|
||||
}
|
||||
(TypeVariants::TyInt(_), TypeVariants::TyInt(_))
|
||||
| (TypeVariants::TyInt(_), TypeVariants::TyUint(_)) => {
|
||||
let from = operand.load_value(fx);
|
||||
let res = crate::common::cton_intcast(fx, from, from_ty, to_ty, true);
|
||||
let res = crate::common::cton_intcast(fx, from, fx.cton_type(to_ty).unwrap(), true);
|
||||
lval.write_cvalue(fx, CValue::ByVal(res, dest_layout));
|
||||
}
|
||||
(TypeVariants::TyFloat(from_flt), TypeVariants::TyFloat(to_flt)) => {
|
||||
@ -516,7 +516,7 @@ pub fn trans_get_discriminant<'a, 'tcx: 'a>(
|
||||
layout::Int(_, signed) => signed,
|
||||
_ => false,
|
||||
};
|
||||
let val = cton_intcast(fx, lldiscr, discr_ty, dest_layout.ty, signed);
|
||||
let val = cton_intcast(fx, lldiscr, fx.cton_type(dest_layout.ty).unwrap(), signed);
|
||||
return CValue::ByVal(val, dest_layout);
|
||||
}
|
||||
layout::Variants::NicheFilling {
|
||||
@ -552,7 +552,7 @@ pub fn trans_get_discriminant<'a, 'tcx: 'a>(
|
||||
lldiscr,
|
||||
*niche_variants.end() as u64 as i64,
|
||||
);
|
||||
let if_true = cton_intcast(fx, lldiscr, discr_ty, dest_layout.ty, false);
|
||||
let if_true = cton_intcast(fx, lldiscr, fx.cton_type(dest_layout.ty).unwrap(), false);
|
||||
let if_false = fx
|
||||
.bcx
|
||||
.ins()
|
||||
@ -565,25 +565,33 @@ pub fn trans_get_discriminant<'a, 'tcx: 'a>(
|
||||
}
|
||||
|
||||
macro_rules! binop_match {
|
||||
(@single $fx:expr, $bug_fmt:expr, $var:expr, $lhs:expr, $rhs:expr, $ret_ty:expr, bug) => {
|
||||
(@single $fx:expr, $bug_fmt:expr, $var:expr, $signed:expr, $lhs:expr, $rhs:expr, $ret_ty:expr, bug) => {
|
||||
bug!("binop {} on {} lhs: {:?} rhs: {:?}", stringify!($var), $bug_fmt, $lhs, $rhs)
|
||||
};
|
||||
(@single $fx:expr, $bug_fmt:expr, $var:expr, $lhs:expr, $rhs:expr, $ret_ty:expr, icmp($cc:ident)) => {{
|
||||
(@single $fx:expr, $bug_fmt:expr, $var:expr, $signed:expr, $lhs:expr, $rhs:expr, $ret_ty:expr, icmp($cc:ident)) => {{
|
||||
assert_eq!($fx.tcx.types.bool, $ret_ty);
|
||||
let ret_layout = $fx.layout_of($ret_ty);
|
||||
let b = $fx.bcx.ins().icmp(IntCC::$cc, $lhs, $rhs);
|
||||
|
||||
// TODO HACK no encoding for icmp.i8
|
||||
use crate::common::cton_intcast;
|
||||
let (lhs, rhs) = (
|
||||
cton_intcast($fx, $lhs, types::I64, $signed),
|
||||
cton_intcast($fx, $rhs, types::I64, $signed),
|
||||
);
|
||||
let b = $fx.bcx.ins().icmp(IntCC::$cc, lhs, rhs);
|
||||
|
||||
CValue::ByVal($fx.bcx.ins().bint(types::I8, b), ret_layout)
|
||||
}};
|
||||
(@single $fx:expr, $bug_fmt:expr, $var:expr, $lhs:expr, $rhs:expr, $ret_ty:expr, fcmp($cc:ident)) => {{
|
||||
(@single $fx:expr, $bug_fmt:expr, $var:expr, $signed:expr, $lhs:expr, $rhs:expr, $ret_ty:expr, fcmp($cc:ident)) => {{
|
||||
assert_eq!($fx.tcx.types.bool, $ret_ty);
|
||||
let ret_layout = $fx.layout_of($ret_ty);
|
||||
let b = $fx.bcx.ins().fcmp(FloatCC::$cc, $lhs, $rhs);
|
||||
CValue::ByVal($fx.bcx.ins().bint(types::I8, b), ret_layout)
|
||||
}};
|
||||
(@single $fx:expr, $bug_fmt:expr, $var:expr, $lhs:expr, $rhs:expr, $ret_ty:expr, custom(|| $body:expr)) => {{
|
||||
(@single $fx:expr, $bug_fmt:expr, $var:expr, $signed:expr, $lhs:expr, $rhs:expr, $ret_ty:expr, custom(|| $body:expr)) => {{
|
||||
$body
|
||||
}};
|
||||
(@single $fx:expr, $bug_fmt:expr, $var:expr, $lhs:expr, $rhs:expr, $ret_ty:expr, $name:ident) => {{
|
||||
(@single $fx:expr, $bug_fmt:expr, $var:expr, $signed:expr, $lhs:expr, $rhs:expr, $ret_ty:expr, $name:ident) => {{
|
||||
let ret_layout = $fx.layout_of($ret_ty);
|
||||
CValue::ByVal($fx.bcx.ins().$name($lhs, $rhs), ret_layout)
|
||||
}};
|
||||
@ -597,7 +605,7 @@ macro_rules! binop_match {
|
||||
let rhs = $rhs.load_value($fx);
|
||||
match ($bin_op, $signed) {
|
||||
$(
|
||||
(BinOp::$var, $sign) => binop_match!(@single $fx, $bug_fmt, $var, lhs, rhs, $ret_ty, $name $( ( $($next)* ) )?),
|
||||
(BinOp::$var, $sign) => binop_match!(@single $fx, $bug_fmt, $var, $signed, lhs, rhs, $ret_ty, $name $( ( $($next)* ) )?),
|
||||
)*
|
||||
}
|
||||
}}
|
||||
|
@ -331,12 +331,10 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
|
||||
pub fn cton_intcast<'a, 'tcx: 'a>(
|
||||
fx: &mut FunctionCx<'a, 'tcx>,
|
||||
val: Value,
|
||||
from: Ty<'tcx>,
|
||||
to: Ty<'tcx>,
|
||||
to: Type,
|
||||
signed: bool,
|
||||
) -> Value {
|
||||
let from = fx.cton_type(from).unwrap();
|
||||
let to = fx.cton_type(to).unwrap();
|
||||
let from = fx.bcx.func.dfg.value_type(val);
|
||||
if from == to {
|
||||
return val;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user