From b8c5053a02f5468e58f856d06586d1a06560d224 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Thu, 26 May 2016 22:53:27 +0300 Subject: [PATCH] trans: use the same messages for both MIR and old arithmetic checks. --- src/librustc_trans/base.rs | 15 ++++++++------- src/librustc_trans/expr.rs | 20 +++++++++++++++----- src/test/run-fail/mod-zero.rs | 2 +- src/test/run-fail/overflowing-add.rs | 2 +- src/test/run-fail/overflowing-lsh-1.rs | 2 +- src/test/run-fail/overflowing-lsh-2.rs | 2 +- src/test/run-fail/overflowing-lsh-3.rs | 2 +- src/test/run-fail/overflowing-lsh-4.rs | 2 +- src/test/run-fail/overflowing-mul.rs | 2 +- src/test/run-fail/overflowing-pow.rs | 2 +- src/test/run-fail/overflowing-rsh-1.rs | 2 +- src/test/run-fail/overflowing-rsh-2.rs | 2 +- src/test/run-fail/overflowing-rsh-3.rs | 2 +- src/test/run-fail/overflowing-rsh-4.rs | 2 +- src/test/run-fail/overflowing-rsh-5.rs | 2 +- src/test/run-fail/overflowing-rsh-6.rs | 2 +- src/test/run-fail/overflowing-sub.rs | 2 +- 17 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 712805061ea..cd20a75db81 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 465ebace1b8..09fd3abd91f 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 093dad5838b..686c3eb2f83 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 1f5297de5aa..ecb8c676cf7 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 a6a898fef19..e277886d003 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 d25982e6016..42cb0f2d55b 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 0d9fcc850bb..8c6623dcf50 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 f8dbd41d8bb..3b7a00a2c73 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 ce8a8c27e52..0e168bf6ffb 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 e9fea9e1141..9172374ec28 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 96400541367..d275792485d 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 c8c7171d7ad..1b888cddf64 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 afcf31f5d69..be5c213493d 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 c4b3d61f2af..820d9611d6a 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 8793a416286..b87be696fcb 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 e9676b6f702..554675686b5 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 96775aef078..1cb207240ca 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() {