Tweak implementation of overflow checking assertions
Extract and reuse logic controlling behaviour of overflow checking assertions instead of duplicating it three times.
This commit is contained in:
parent
e42bea9fde
commit
edb0717e7c
15
src/base.rs
15
src/base.rs
@ -346,17 +346,10 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
|
|||||||
crate::abi::codegen_return(fx);
|
crate::abi::codegen_return(fx);
|
||||||
}
|
}
|
||||||
TerminatorKind::Assert { cond, expected, msg, target, cleanup: _ } => {
|
TerminatorKind::Assert { cond, expected, msg, target, cleanup: _ } => {
|
||||||
if !fx.tcx.sess.overflow_checks() {
|
if !fx.tcx.sess.overflow_checks() && msg.is_optional_overflow_check() {
|
||||||
let overflow_not_to_check = match msg {
|
let target = fx.get_block(*target);
|
||||||
AssertKind::OverflowNeg(..) => true,
|
fx.bcx.ins().jump(target, &[]);
|
||||||
AssertKind::Overflow(op, ..) => op.is_checkable(),
|
continue;
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
if overflow_not_to_check {
|
|
||||||
let target = fx.get_block(*target);
|
|
||||||
fx.bcx.ins().jump(target, &[]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
let cond = codegen_operand(fx, cond).load_scalar(fx);
|
let cond = codegen_operand(fx, cond).load_scalar(fx);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user