Skip to content

Commit 9505d60

Browse files
committed
Cast rhs to lhs type for shl and shr
1 parent b4e55cd commit 9505d60

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

example/std_example.rs

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ fn main() {
4848
assert_eq!(0xFEDCBA987654321123456789ABCDEFu128 as i128 >> 64, 0xFEDCBA98765432i128);
4949
assert_eq!(353985398u128 * 932490u128, 330087843781020u128);
5050

51+
let _a = 1u32 << 2u8;
52+
5153
unsafe {
5254
test_simd();
5355
}

src/num.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,20 @@ pub fn trans_int_binop<'a, 'tcx: 'a>(
129129
BinOp::BitXor => b.bxor(lhs, rhs),
130130
BinOp::BitAnd => b.band(lhs, rhs),
131131
BinOp::BitOr => b.bor(lhs, rhs),
132-
BinOp::Shl => b.ishl(lhs, rhs),
133-
BinOp::Shr => if signed { b.sshr(lhs, rhs) } else { b.ushr(lhs, rhs) },
132+
BinOp::Shl => {
133+
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
134+
let rhs = clif_intcast(fx, rhs, lhs_ty, false);
135+
fx.bcx.ins().ishl(lhs, rhs)
136+
}
137+
BinOp::Shr => {
138+
let lhs_ty = fx.bcx.func.dfg.value_type(lhs);
139+
let rhs = clif_intcast(fx, rhs, lhs_ty, false);
140+
if signed {
141+
fx.bcx.ins().sshr(lhs, rhs)
142+
} else {
143+
fx.bcx.ins().ushr(lhs, rhs)
144+
}
145+
}
134146
// Compare binops handles by `codegen_binop`.
135147
_ => unreachable!("{:?}({:?}, {:?})", bin_op, in_lhs.layout().ty, in_rhs.layout().ty),
136148
};

0 commit comments

Comments
 (0)