trans: use the same messages for both MIR and old arithmetic checks.
This commit is contained in:
parent
1447fbf183
commit
b8c5053a02
@ -769,12 +769,12 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
|
||||
rhs: ValueRef,
|
||||
rhs_t: Ty<'tcx>)
|
||||
-> Block<'blk, 'tcx> {
|
||||
let (zero_text, overflow_text) = if divrem.node == hir::BiDiv {
|
||||
("attempted to divide by zero",
|
||||
"attempted to divide with overflow")
|
||||
use rustc_const_math::{ConstMathErr, Op};
|
||||
|
||||
let (zero_err, overflow_err) = if divrem.node == hir::BiDiv {
|
||||
(ConstMathErr::DivisionByZero, ConstMathErr::Overflow(Op::Div))
|
||||
} else {
|
||||
("attempted remainder with a divisor of zero",
|
||||
"attempted remainder with overflow")
|
||||
(ConstMathErr::RemainderByZero, ConstMathErr::Overflow(Op::Rem))
|
||||
};
|
||||
let debug_loc = call_info.debug_loc();
|
||||
|
||||
@ -802,7 +802,7 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
|
||||
}
|
||||
};
|
||||
let bcx = with_cond(cx, is_zero, |bcx| {
|
||||
controlflow::trans_fail(bcx, call_info, InternedString::new(zero_text))
|
||||
controlflow::trans_fail(bcx, call_info, InternedString::new(zero_err.description()))
|
||||
});
|
||||
|
||||
// To quote LLVM's documentation for the sdiv instruction:
|
||||
@ -828,7 +828,8 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
|
||||
C_integral(llty, min, true),
|
||||
debug_loc);
|
||||
with_cond(bcx, is_min, |bcx| {
|
||||
controlflow::trans_fail(bcx, call_info, InternedString::new(overflow_text))
|
||||
controlflow::trans_fail(bcx, call_info,
|
||||
InternedString::new(overflow_err.description()))
|
||||
})
|
||||
})
|
||||
} else {
|
||||
|
@ -2220,6 +2220,8 @@ impl OverflowOpViaIntrinsic {
|
||||
rhs: ValueRef,
|
||||
binop_debug_loc: DebugLoc)
|
||||
-> (Block<'blk, 'tcx>, ValueRef) {
|
||||
use rustc_const_math::{ConstMathErr, Op};
|
||||
|
||||
let llfn = self.to_intrinsic(bcx, lhs_t);
|
||||
|
||||
let val = Call(bcx, llfn, &[lhs, rhs], binop_debug_loc);
|
||||
@ -2233,10 +2235,16 @@ impl OverflowOpViaIntrinsic {
|
||||
let expected = Call(bcx, expect, &[cond, C_bool(bcx.ccx(), false)],
|
||||
binop_debug_loc);
|
||||
|
||||
let op = match *self {
|
||||
OverflowOpViaIntrinsic::Add => Op::Add,
|
||||
OverflowOpViaIntrinsic::Sub => Op::Sub,
|
||||
OverflowOpViaIntrinsic::Mul => Op::Mul
|
||||
};
|
||||
|
||||
let bcx =
|
||||
base::with_cond(bcx, expected, |bcx|
|
||||
controlflow::trans_fail(bcx, info,
|
||||
InternedString::new("arithmetic operation overflowed")));
|
||||
InternedString::new(ConstMathErr::Overflow(op).description())));
|
||||
|
||||
(bcx, result)
|
||||
}
|
||||
@ -2252,6 +2260,8 @@ impl OverflowOpViaInputCheck {
|
||||
binop_debug_loc: DebugLoc)
|
||||
-> (Block<'blk, 'tcx>, ValueRef)
|
||||
{
|
||||
use rustc_const_math::{ConstMathErr, Op};
|
||||
|
||||
let lhs_llty = val_ty(lhs);
|
||||
let rhs_llty = val_ty(rhs);
|
||||
|
||||
@ -2266,16 +2276,16 @@ impl OverflowOpViaInputCheck {
|
||||
|
||||
let outer_bits = And(bcx, rhs, invert_mask, binop_debug_loc);
|
||||
let cond = build_nonzero_check(bcx, outer_bits, binop_debug_loc);
|
||||
let result = match *self {
|
||||
let (result, op) = match *self {
|
||||
OverflowOpViaInputCheck::Shl =>
|
||||
build_unchecked_lshift(bcx, lhs, rhs, binop_debug_loc),
|
||||
(build_unchecked_lshift(bcx, lhs, rhs, binop_debug_loc), Op::Shl),
|
||||
OverflowOpViaInputCheck::Shr =>
|
||||
build_unchecked_rshift(bcx, lhs_t, lhs, rhs, binop_debug_loc),
|
||||
(build_unchecked_rshift(bcx, lhs_t, lhs, rhs, binop_debug_loc), Op::Shr)
|
||||
};
|
||||
let bcx =
|
||||
base::with_cond(bcx, cond, |bcx|
|
||||
controlflow::trans_fail(bcx, info,
|
||||
InternedString::new("shift operation overflowed")));
|
||||
InternedString::new(ConstMathErr::Overflow(op).description())));
|
||||
|
||||
(bcx, result)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:attempted remainder with a divisor of zero
|
||||
// error-pattern:attempted to calculate the remainder with a divisor of zero
|
||||
|
||||
fn main() {
|
||||
let y = 0;
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'arithmetic operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to add with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to shift left with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
#![warn(exceeding_bitshifts)]
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to shift left with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
#![warn(exceeding_bitshifts)]
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to shift left with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
#![warn(exceeding_bitshifts)]
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to shift left with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
// This function is checking that our automatic truncation does not
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'arithmetic operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to multiply with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
fn main() {
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'arithmetic operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to multiply with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
fn main() {
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to shift right with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
#![warn(exceeding_bitshifts)]
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to shift right with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
#![warn(exceeding_bitshifts)]
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to shift right with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
#![warn(exceeding_bitshifts)]
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to shift right with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
// This function is checking that our (type-based) automatic
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to shift right with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
#![warn(exceeding_bitshifts)]
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'shift operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to shift right with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
#![warn(exceeding_bitshifts)]
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
// ignore-pretty : (#23623) problems when ending with // comments
|
||||
|
||||
// error-pattern:thread 'main' panicked at 'arithmetic operation overflowed'
|
||||
// error-pattern:thread 'main' panicked at 'attempted to subtract with overflow'
|
||||
// compile-flags: -C debug-assertions
|
||||
|
||||
fn main() {
|
||||
|
Loading…
Reference in New Issue
Block a user