diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 712805061ea8c..cd20a75db81bf 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -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 { diff --git a/src/librustc_trans/expr.rs b/src/librustc_trans/expr.rs index 465ebace1b830..09fd3abd91f11 100644 --- a/src/librustc_trans/expr.rs +++ b/src/librustc_trans/expr.rs @@ -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) } diff --git a/src/test/run-fail/mod-zero.rs b/src/test/run-fail/mod-zero.rs index 093dad5838b60..686c3eb2f83b8 100644 --- a/src/test/run-fail/mod-zero.rs +++ b/src/test/run-fail/mod-zero.rs @@ -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; diff --git a/src/test/run-fail/overflowing-add.rs b/src/test/run-fail/overflowing-add.rs index 1f5297de5aa8d..ecb8c676cf700 100644 --- a/src/test/run-fail/overflowing-add.rs +++ b/src/test/run-fail/overflowing-add.rs @@ -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 diff --git a/src/test/run-fail/overflowing-lsh-1.rs b/src/test/run-fail/overflowing-lsh-1.rs index a6a898fef1997..e277886d003dc 100644 --- a/src/test/run-fail/overflowing-lsh-1.rs +++ b/src/test/run-fail/overflowing-lsh-1.rs @@ -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)] diff --git a/src/test/run-fail/overflowing-lsh-2.rs b/src/test/run-fail/overflowing-lsh-2.rs index d25982e601652..42cb0f2d55bc1 100644 --- a/src/test/run-fail/overflowing-lsh-2.rs +++ b/src/test/run-fail/overflowing-lsh-2.rs @@ -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)] diff --git a/src/test/run-fail/overflowing-lsh-3.rs b/src/test/run-fail/overflowing-lsh-3.rs index 0d9fcc850bbb0..8c6623dcf50ce 100644 --- a/src/test/run-fail/overflowing-lsh-3.rs +++ b/src/test/run-fail/overflowing-lsh-3.rs @@ -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)] diff --git a/src/test/run-fail/overflowing-lsh-4.rs b/src/test/run-fail/overflowing-lsh-4.rs index f8dbd41d8bb00..3b7a00a2c73c6 100644 --- a/src/test/run-fail/overflowing-lsh-4.rs +++ b/src/test/run-fail/overflowing-lsh-4.rs @@ -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 diff --git a/src/test/run-fail/overflowing-mul.rs b/src/test/run-fail/overflowing-mul.rs index ce8a8c27e52c9..0e168bf6ffbc6 100644 --- a/src/test/run-fail/overflowing-mul.rs +++ b/src/test/run-fail/overflowing-mul.rs @@ -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() { diff --git a/src/test/run-fail/overflowing-pow.rs b/src/test/run-fail/overflowing-pow.rs index e9fea9e1141ed..9172374ec2818 100644 --- a/src/test/run-fail/overflowing-pow.rs +++ b/src/test/run-fail/overflowing-pow.rs @@ -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() { diff --git a/src/test/run-fail/overflowing-rsh-1.rs b/src/test/run-fail/overflowing-rsh-1.rs index 9640054136744..d275792485d51 100644 --- a/src/test/run-fail/overflowing-rsh-1.rs +++ b/src/test/run-fail/overflowing-rsh-1.rs @@ -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)] diff --git a/src/test/run-fail/overflowing-rsh-2.rs b/src/test/run-fail/overflowing-rsh-2.rs index c8c7171d7ad57..1b888cddf6443 100644 --- a/src/test/run-fail/overflowing-rsh-2.rs +++ b/src/test/run-fail/overflowing-rsh-2.rs @@ -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)] diff --git a/src/test/run-fail/overflowing-rsh-3.rs b/src/test/run-fail/overflowing-rsh-3.rs index afcf31f5d69b5..be5c213493d6d 100644 --- a/src/test/run-fail/overflowing-rsh-3.rs +++ b/src/test/run-fail/overflowing-rsh-3.rs @@ -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)] diff --git a/src/test/run-fail/overflowing-rsh-4.rs b/src/test/run-fail/overflowing-rsh-4.rs index c4b3d61f2af48..820d9611d6acb 100644 --- a/src/test/run-fail/overflowing-rsh-4.rs +++ b/src/test/run-fail/overflowing-rsh-4.rs @@ -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 diff --git a/src/test/run-fail/overflowing-rsh-5.rs b/src/test/run-fail/overflowing-rsh-5.rs index 8793a416286e3..b87be696fcb21 100644 --- a/src/test/run-fail/overflowing-rsh-5.rs +++ b/src/test/run-fail/overflowing-rsh-5.rs @@ -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)] diff --git a/src/test/run-fail/overflowing-rsh-6.rs b/src/test/run-fail/overflowing-rsh-6.rs index e9676b6f70299..554675686b5e2 100644 --- a/src/test/run-fail/overflowing-rsh-6.rs +++ b/src/test/run-fail/overflowing-rsh-6.rs @@ -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)] diff --git a/src/test/run-fail/overflowing-sub.rs b/src/test/run-fail/overflowing-sub.rs index 96775aef07836..1cb207240ca49 100644 --- a/src/test/run-fail/overflowing-sub.rs +++ b/src/test/run-fail/overflowing-sub.rs @@ -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() {