Skip to content

Commit

Permalink
Tweak implementation of overflow checking assertions
Browse files Browse the repository at this point in the history
Extract and reuse logic controlling behaviour of overflow checking
assertions instead of duplicating it three times.
  • Loading branch information
tmiasko committed Mar 16, 2023
1 parent e42bea9 commit edb0717
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,17 +346,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
crate::abi::codegen_return(fx);
}
TerminatorKind::Assert { cond, expected, msg, target, cleanup: _ } => {
if !fx.tcx.sess.overflow_checks() {
let overflow_not_to_check = match msg {
AssertKind::OverflowNeg(..) => true,
AssertKind::Overflow(op, ..) => op.is_checkable(),
_ => false,
};
if overflow_not_to_check {
let target = fx.get_block(*target);
fx.bcx.ins().jump(target, &[]);
continue;
}
if !fx.tcx.sess.overflow_checks() && msg.is_optional_overflow_check() {
let target = fx.get_block(*target);
fx.bcx.ins().jump(target, &[]);
continue;
}
let cond = codegen_operand(fx, cond).load_scalar(fx);

Expand Down

0 comments on commit edb0717

Please sign in to comment.