trans: use the same messages for both MIR and old arithmetic checks.

This commit is contained in:
Eduard Burtescu 2016-05-26 22:53:27 +03:00
parent 1447fbf183
commit b8c5053a02
17 changed files with 38 additions and 27 deletions

View File

@ -769,12 +769,12 @@ pub fn fail_if_zero_or_overflows<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
rhs: ValueRef, rhs: ValueRef,
rhs_t: Ty<'tcx>) rhs_t: Ty<'tcx>)
-> Block<'blk, 'tcx> { -> Block<'blk, 'tcx> {
let (zero_text, overflow_text) = if divrem.node == hir::BiDiv { use rustc_const_math::{ConstMathErr, Op};
("attempted to divide by zero",
"attempted to divide with overflow") let (zero_err, overflow_err) = if divrem.node == hir::BiDiv {
(ConstMathErr::DivisionByZero, ConstMathErr::Overflow(Op::Div))
} else { } else {
("attempted remainder with a divisor of zero", (ConstMathErr::RemainderByZero, ConstMathErr::Overflow(Op::Rem))
"attempted remainder with overflow")
}; };
let debug_loc = call_info.debug_loc(); 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| { 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: // 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), C_integral(llty, min, true),
debug_loc); debug_loc);
with_cond(bcx, is_min, |bcx| { 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 { } else {

View File

@ -2220,6 +2220,8 @@ impl OverflowOpViaIntrinsic {
rhs: ValueRef, rhs: ValueRef,
binop_debug_loc: DebugLoc) binop_debug_loc: DebugLoc)
-> (Block<'blk, 'tcx>, ValueRef) { -> (Block<'blk, 'tcx>, ValueRef) {
use rustc_const_math::{ConstMathErr, Op};
let llfn = self.to_intrinsic(bcx, lhs_t); let llfn = self.to_intrinsic(bcx, lhs_t);
let val = Call(bcx, llfn, &[lhs, rhs], binop_debug_loc); 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)], let expected = Call(bcx, expect, &[cond, C_bool(bcx.ccx(), false)],
binop_debug_loc); binop_debug_loc);
let op = match *self {
OverflowOpViaIntrinsic::Add => Op::Add,
OverflowOpViaIntrinsic::Sub => Op::Sub,
OverflowOpViaIntrinsic::Mul => Op::Mul
};
let bcx = let bcx =
base::with_cond(bcx, expected, |bcx| base::with_cond(bcx, expected, |bcx|
controlflow::trans_fail(bcx, info, controlflow::trans_fail(bcx, info,
InternedString::new("arithmetic operation overflowed"))); InternedString::new(ConstMathErr::Overflow(op).description())));
(bcx, result) (bcx, result)
} }
@ -2252,6 +2260,8 @@ impl OverflowOpViaInputCheck {
binop_debug_loc: DebugLoc) binop_debug_loc: DebugLoc)
-> (Block<'blk, 'tcx>, ValueRef) -> (Block<'blk, 'tcx>, ValueRef)
{ {
use rustc_const_math::{ConstMathErr, Op};
let lhs_llty = val_ty(lhs); let lhs_llty = val_ty(lhs);
let rhs_llty = val_ty(rhs); let rhs_llty = val_ty(rhs);
@ -2266,16 +2276,16 @@ impl OverflowOpViaInputCheck {
let outer_bits = And(bcx, rhs, invert_mask, binop_debug_loc); let outer_bits = And(bcx, rhs, invert_mask, binop_debug_loc);
let cond = build_nonzero_check(bcx, outer_bits, 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 => OverflowOpViaInputCheck::Shl =>
build_unchecked_lshift(bcx, lhs, rhs, binop_debug_loc), (build_unchecked_lshift(bcx, lhs, rhs, binop_debug_loc), Op::Shl),
OverflowOpViaInputCheck::Shr => 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 = let bcx =
base::with_cond(bcx, cond, |bcx| base::with_cond(bcx, cond, |bcx|
controlflow::trans_fail(bcx, info, controlflow::trans_fail(bcx, info,
InternedString::new("shift operation overflowed"))); InternedString::new(ConstMathErr::Overflow(op).description())));
(bcx, result) (bcx, result)
} }

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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() { fn main() {
let y = 0; let y = 0;

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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 // compile-flags: -C debug-assertions

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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 // compile-flags: -C debug-assertions
#![warn(exceeding_bitshifts)] #![warn(exceeding_bitshifts)]

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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 // compile-flags: -C debug-assertions
#![warn(exceeding_bitshifts)] #![warn(exceeding_bitshifts)]

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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 // compile-flags: -C debug-assertions
#![warn(exceeding_bitshifts)] #![warn(exceeding_bitshifts)]

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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 // compile-flags: -C debug-assertions
// This function is checking that our automatic truncation does not // This function is checking that our automatic truncation does not

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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 // compile-flags: -C debug-assertions
fn main() { fn main() {

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // 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 // compile-flags: -C debug-assertions
fn main() { fn main() {

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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 // compile-flags: -C debug-assertions
#![warn(exceeding_bitshifts)] #![warn(exceeding_bitshifts)]

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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 // compile-flags: -C debug-assertions
#![warn(exceeding_bitshifts)] #![warn(exceeding_bitshifts)]

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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 // compile-flags: -C debug-assertions
#![warn(exceeding_bitshifts)] #![warn(exceeding_bitshifts)]

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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 // compile-flags: -C debug-assertions
// This function is checking that our (type-based) automatic // This function is checking that our (type-based) automatic

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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 // compile-flags: -C debug-assertions
#![warn(exceeding_bitshifts)] #![warn(exceeding_bitshifts)]

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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 // compile-flags: -C debug-assertions
#![warn(exceeding_bitshifts)] #![warn(exceeding_bitshifts)]

View File

@ -10,7 +10,7 @@
// ignore-pretty : (#23623) problems when ending with // comments // 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 // compile-flags: -C debug-assertions
fn main() { fn main() {