1
Fork 0

Rollup merge of #109234 - tmiasko:overflow-checks, r=cjgillot

Tweak implementation of overflow checking assertions

Extract and reuse logic controlling behaviour of overflow checking assertions instead of duplicating it three times.

r? `@cjgillot`
This commit is contained in:
Matthias Krüger 2023-03-18 12:04:23 +01:00 committed by GitHub
commit a48d83d556
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 41 deletions

View file

@ -563,15 +563,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
// with #[rustc_inherit_overflow_checks] and inlined from
// another crate (mostly core::num generic/#[inline] fns),
// while the current crate doesn't use overflow checks.
if !bx.cx().check_overflow() {
let overflow_not_to_check = match msg {
AssertKind::OverflowNeg(..) => true,
AssertKind::Overflow(op, ..) => op.is_checkable(),
_ => false,
};
if overflow_not_to_check {
const_cond = Some(expected);
}
if !bx.cx().check_overflow() && msg.is_optional_overflow_check() {
const_cond = Some(expected);
}
// Don't codegen the panic block if success if known.