Cast rhs to lhs type for shl and shr
This commit is contained in:
parent
b4e55cdedd
commit
9505d60a24
2 changed files with 16 additions and 2 deletions
|
@ -48,6 +48,8 @@ fn main() {
|
|||
assert_eq!(0xFEDCBA987654321123456789ABCDEFu128 as i128 >> 64, 0xFEDCBA98765432i128);
|
||||
assert_eq!(353985398u128 * 932490u128, 330087843781020u128);
|
||||
|
||||
let _a = 1u32 << 2u8;
|
||||
|
||||
unsafe {
|
||||
test_simd();
|
||||
}
|
||||
|
|
16
src/num.rs
16
src/num.rs
|
@ -129,8 +129,20 @@ pub fn trans_int_binop<'a, 'tcx: 'a>(
|
|||
BinOp::BitXor => b.bxor(lhs, rhs),
|
||||
BinOp::BitAnd => b.band(lhs, rhs),
|
||||
BinOp::BitOr => b.bor(lhs, rhs),
|
||||
BinOp::Shl => b.ishl(lhs, rhs),
|
||||
BinOp::Shr => if signed { b.sshr(lhs, rhs) } else { b.ushr(lhs, rhs) },
|
||||
BinOp::Shl => {
|
||||
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
|
||||
let rhs = clif_intcast(fx, rhs, lhs_ty, false);
|
||||
fx.bcx.ins().ishl(lhs, rhs)
|
||||
}
|
||||
BinOp::Shr => {
|
||||
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
|
||||
let rhs = clif_intcast(fx, rhs, lhs_ty, false);
|
||||
if signed {
|
||||
fx.bcx.ins().sshr(lhs, rhs)
|
||||
} else {
|
||||
fx.bcx.ins().ushr(lhs, rhs)
|
||||
}
|
||||
}
|
||||
// Compare binops handles by `codegen_binop`.
|
||||
_ => unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs.layout().ty, in_rhs.layout().ty),
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue