@@ -2220,6 +2220,8 @@ impl OverflowOpViaIntrinsic {
22202220 rhs : ValueRef ,
22212221 binop_debug_loc : DebugLoc )
22222222 -> ( Block < ' blk , ' tcx > , ValueRef ) {
2223+ use rustc_const_math:: { ConstMathErr , Op } ;
2224+
22232225 let llfn = self . to_intrinsic ( bcx, lhs_t) ;
22242226
22252227 let val = Call ( bcx, llfn, & [ lhs, rhs] , binop_debug_loc) ;
@@ -2233,10 +2235,16 @@ impl OverflowOpViaIntrinsic {
22332235 let expected = Call ( bcx, expect, & [ cond, C_bool ( bcx. ccx ( ) , false ) ] ,
22342236 binop_debug_loc) ;
22352237
2238+ let op = match * self {
2239+ OverflowOpViaIntrinsic :: Add => Op :: Add ,
2240+ OverflowOpViaIntrinsic :: Sub => Op :: Sub ,
2241+ OverflowOpViaIntrinsic :: Mul => Op :: Mul
2242+ } ;
2243+
22362244 let bcx =
22372245 base:: with_cond ( bcx, expected, |bcx|
22382246 controlflow:: trans_fail ( bcx, info,
2239- InternedString :: new ( "arithmetic operation overflowed" ) ) ) ;
2247+ InternedString :: new ( ConstMathErr :: Overflow ( op ) . description ( ) ) ) ) ;
22402248
22412249 ( bcx, result)
22422250 }
@@ -2252,6 +2260,8 @@ impl OverflowOpViaInputCheck {
22522260 binop_debug_loc : DebugLoc )
22532261 -> ( Block < ' blk , ' tcx > , ValueRef )
22542262 {
2263+ use rustc_const_math:: { ConstMathErr , Op } ;
2264+
22552265 let lhs_llty = val_ty ( lhs) ;
22562266 let rhs_llty = val_ty ( rhs) ;
22572267
@@ -2266,16 +2276,16 @@ impl OverflowOpViaInputCheck {
22662276
22672277 let outer_bits = And ( bcx, rhs, invert_mask, binop_debug_loc) ;
22682278 let cond = build_nonzero_check ( bcx, outer_bits, binop_debug_loc) ;
2269- let result = match * self {
2279+ let ( result, op ) = match * self {
22702280 OverflowOpViaInputCheck :: Shl =>
2271- build_unchecked_lshift ( bcx, lhs, rhs, binop_debug_loc) ,
2281+ ( build_unchecked_lshift ( bcx, lhs, rhs, binop_debug_loc) , Op :: Shl ) ,
22722282 OverflowOpViaInputCheck :: Shr =>
2273- build_unchecked_rshift ( bcx, lhs_t, lhs, rhs, binop_debug_loc) ,
2283+ ( build_unchecked_rshift ( bcx, lhs_t, lhs, rhs, binop_debug_loc) , Op :: Shr )
22742284 } ;
22752285 let bcx =
22762286 base:: with_cond ( bcx, cond, |bcx|
22772287 controlflow:: trans_fail ( bcx, info,
2278- InternedString :: new ( "shift operation overflowed" ) ) ) ;
2288+ InternedString :: new ( ConstMathErr :: Overflow ( op ) . description ( ) ) ) ) ;
22792289
22802290 ( bcx, result)
22812291 }
0 commit comments