Skip to content

Commit c7fa94b

Browse files
committed
Fix checked binops when overflow checks are disabled
1 parent fe20f8c commit c7fa94b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/base.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,11 @@ pub fn trans_int_binop<'a, 'tcx: 'a>(
831831
);
832832
}
833833

834+
match out_ty.sty {
835+
ty::Bool | ty::Uint(_) | ty::Int(_) => {}
836+
_ => unreachable!("Out ty {:?} is not an integer or bool", out_ty),
837+
}
838+
834839
if let Some(res) = crate::codegen_i128::maybe_codegen(fx, bin_op, false, signed, lhs, rhs, out_ty) {
835840
return res;
836841
}
@@ -875,7 +880,9 @@ pub fn trans_checked_int_binop<'a, 'tcx: 'a>(
875880
signed: bool,
876881
) -> CValue<'tcx> {
877882
if !fx.tcx.sess.overflow_checks() {
878-
return trans_int_binop(fx, bin_op, in_lhs, in_rhs, out_ty, signed);
883+
let val = trans_int_binop(fx, bin_op, in_lhs, in_rhs, in_lhs.layout().ty, signed).load_scalar(fx);
884+
let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
885+
return CValue::by_val_pair(val, is_overflow, fx.layout_of(out_ty));
879886
}
880887

881888
if bin_op != BinOp::Shl && bin_op != BinOp::Shr {

0 commit comments

Comments
 (0)