Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6414f03

Browse files
committed
Don't omit overflow checks for *_with_overflow intrinsics when compiling without debug assertions
1 parent 19a3bfe commit 6414f03

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/base.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,20 @@ fn trans_stmt<'a, 'tcx: 'a>(
334334
let lhs = trans_operand(fx, lhs);
335335
let rhs = trans_operand(fx, rhs);
336336

337-
let res = match ty.sty {
338-
ty::Uint(_) => {
339-
trans_checked_int_binop(fx, *bin_op, lhs, rhs, lval.layout().ty, false)
340-
}
341-
ty::Int(_) => {
342-
trans_checked_int_binop(fx, *bin_op, lhs, rhs, lval.layout().ty, true)
343-
}
337+
let signed = match ty.sty {
338+
ty::Uint(_) => false,
339+
ty::Int(_) => true,
344340
_ => unimplemented!("checked binop {:?} for {:?}", bin_op, ty),
345341
};
342+
343+
let res = if !fx.tcx.sess.overflow_checks() {
344+
let val = trans_int_binop(fx, *bin_op, lhs, rhs, lhs.layout().ty, signed).load_scalar(fx);
345+
let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
346+
CValue::by_val_pair(val, is_overflow, lval.layout())
347+
} else {
348+
trans_checked_int_binop(fx, *bin_op, lhs, rhs, lval.layout().ty, signed)
349+
};
350+
346351
lval.write_cvalue(fx, res);
347352
}
348353
Rvalue::UnaryOp(un_op, operand) => {
@@ -843,12 +848,6 @@ pub fn trans_checked_int_binop<'a, 'tcx: 'a>(
843848
out_ty: Ty<'tcx>,
844849
signed: bool,
845850
) -> CValue<'tcx> {
846-
if !fx.tcx.sess.overflow_checks() {
847-
let val = trans_int_binop(fx, bin_op, in_lhs, in_rhs, in_lhs.layout().ty, signed).load_scalar(fx);
848-
let is_overflow = fx.bcx.ins().iconst(types::I8, 0);
849-
return CValue::by_val_pair(val, is_overflow, fx.layout_of(out_ty));
850-
}
851-
852851
if bin_op != BinOp::Shl && bin_op != BinOp::Shr {
853852
assert_eq!(
854853
in_lhs.layout().ty,

0 commit comments

Comments
 (0)