diff options
| author | Wesley Wiser <wwiser@gmail.com> | 2019-09-08 21:02:54 -0400 |
|---|---|---|
| committer | Wesley Wiser <wwiser@gmail.com> | 2019-09-27 20:11:12 -0400 |
| commit | 11eb91f412b2693c970216099b9d910498b0b789 (patch) | |
| tree | b7c419e9b0ef16a45b9710c6f9351c5ccb8179ca | |
| parent | 644d4f3ee93b49ee773b667a970a552983d5e8fa (diff) | |
| download | rust-11eb91f412b2693c970216099b9d910498b0b789.tar.gz rust-11eb91f412b2693c970216099b9d910498b0b789.zip | |
[const-prop] Replace `CheckedBinaryOp` handling with use of `InterpCx`
| -rw-r--r-- | src/librustc_mir/transform/const_prop.rs | 28 | ||||
| -rw-r--r-- | src/test/run-fail/overflowing-lsh-1.rs | 1 | ||||
| -rw-r--r-- | src/test/run-fail/overflowing-lsh-2.rs | 1 | ||||
| -rw-r--r-- | src/test/run-fail/overflowing-lsh-3.rs | 1 | ||||
| -rw-r--r-- | src/test/run-fail/overflowing-lsh-4.rs | 1 | ||||
| -rw-r--r-- | src/test/run-fail/overflowing-rsh-1.rs | 1 | ||||
| -rw-r--r-- | src/test/run-fail/overflowing-rsh-2.rs | 1 | ||||
| -rw-r--r-- | src/test/run-fail/overflowing-rsh-3.rs | 1 | ||||
| -rw-r--r-- | src/test/run-fail/overflowing-rsh-4.rs | 1 |
9 files changed, 18 insertions, 18 deletions
diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index f172071a8fb..865afefa649 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -312,7 +312,8 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { Rvalue::Use(_) | Rvalue::Len(_) | Rvalue::Cast(..) | - Rvalue::NullaryOp(..) => { + Rvalue::NullaryOp(..) | + Rvalue::CheckedBinaryOp(..) => { self.use_ecx(source_info, |this| { this.ecx.eval_rvalue_into_place(rvalue, place)?; this.ecx.eval_place_to_op(place, Some(place_layout)) @@ -348,7 +349,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { this.ecx.eval_place_to_op(place, Some(place_layout)) }) } - Rvalue::CheckedBinaryOp(op, ref left, ref right) | Rvalue::BinaryOp(op, ref left, ref right) => { trace!("rvalue binop {:?} for {:?} and {:?}", op, left, right); let right = self.eval_operand(right, source_info)?; @@ -403,23 +403,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { let (val, overflow, _ty) = self.use_ecx(source_info, |this| { this.ecx.overflowing_binary_op(op, l, r) })?; - let val = if let Rvalue::CheckedBinaryOp(..) = *rvalue { - Immediate::ScalarPair( - val.into(), - Scalar::from_bool(overflow).into(), - ) - } else { - // We check overflow in debug mode already - // so should only check in release mode. - if !self.tcx.sess.overflow_checks() && overflow { - let err = err_panic!(Overflow(op)).into(); - let _: Option<()> = self.use_ecx(source_info, |_| Err(err)); - return None; - } - Immediate::Scalar(val.into()) - }; + // We check overflow in debug mode already + // so should only check in release mode. + if !self.tcx.sess.overflow_checks() && overflow { + let err = err_panic!(Overflow(op)).into(); + let _: Option<()> = self.use_ecx(source_info, |_| Err(err)); + return None; + } let res = ImmTy { - imm: val, + imm: Immediate::Scalar(val.into()), layout: place_layout, }; Some(res.into()) diff --git a/src/test/run-fail/overflowing-lsh-1.rs b/src/test/run-fail/overflowing-lsh-1.rs index c69da0f49ad..37fbf01e487 100644 --- a/src/test/run-fail/overflowing-lsh-1.rs +++ b/src/test/run-fail/overflowing-lsh-1.rs @@ -2,6 +2,7 @@ // compile-flags: -C debug-assertions #![warn(exceeding_bitshifts)] +#![warn(const_err)] fn main() { let _x = 1_i32 << 32; diff --git a/src/test/run-fail/overflowing-lsh-2.rs b/src/test/run-fail/overflowing-lsh-2.rs index 21659bd5239..7b0b37dfed0 100644 --- a/src/test/run-fail/overflowing-lsh-2.rs +++ b/src/test/run-fail/overflowing-lsh-2.rs @@ -2,6 +2,7 @@ // compile-flags: -C debug-assertions #![warn(exceeding_bitshifts)] +#![warn(const_err)] fn main() { let _x = 1 << -1; diff --git a/src/test/run-fail/overflowing-lsh-3.rs b/src/test/run-fail/overflowing-lsh-3.rs index 8f06cd11533..1768a8e6d31 100644 --- a/src/test/run-fail/overflowing-lsh-3.rs +++ b/src/test/run-fail/overflowing-lsh-3.rs @@ -2,6 +2,7 @@ // compile-flags: -C debug-assertions #![warn(exceeding_bitshifts)] +#![warn(const_err)] fn main() { let _x = 1_u64 << 64; diff --git a/src/test/run-fail/overflowing-lsh-4.rs b/src/test/run-fail/overflowing-lsh-4.rs index 084c147094d..ec304b4144e 100644 --- a/src/test/run-fail/overflowing-lsh-4.rs +++ b/src/test/run-fail/overflowing-lsh-4.rs @@ -5,6 +5,7 @@ // sidestep the overflow checking. #![warn(exceeding_bitshifts)] +#![warn(const_err)] fn main() { // this signals overflow when checking is on diff --git a/src/test/run-fail/overflowing-rsh-1.rs b/src/test/run-fail/overflowing-rsh-1.rs index 24a77da896d..14514540c06 100644 --- a/src/test/run-fail/overflowing-rsh-1.rs +++ b/src/test/run-fail/overflowing-rsh-1.rs @@ -2,6 +2,7 @@ // compile-flags: -C debug-assertions #![warn(exceeding_bitshifts)] +#![warn(const_err)] fn main() { let _x = -1_i32 >> 32; diff --git a/src/test/run-fail/overflowing-rsh-2.rs b/src/test/run-fail/overflowing-rsh-2.rs index b5615cacc20..83dcbd13d2a 100644 --- a/src/test/run-fail/overflowing-rsh-2.rs +++ b/src/test/run-fail/overflowing-rsh-2.rs @@ -2,6 +2,7 @@ // compile-flags: -C debug-assertions #![warn(exceeding_bitshifts)] +#![warn(const_err)] fn main() { let _x = -1_i32 >> -1; diff --git a/src/test/run-fail/overflowing-rsh-3.rs b/src/test/run-fail/overflowing-rsh-3.rs index 7598e026d81..3521c050659 100644 --- a/src/test/run-fail/overflowing-rsh-3.rs +++ b/src/test/run-fail/overflowing-rsh-3.rs @@ -2,6 +2,7 @@ // compile-flags: -C debug-assertions #![warn(exceeding_bitshifts)] +#![warn(const_err)] fn main() { let _x = -1_i64 >> 64; diff --git a/src/test/run-fail/overflowing-rsh-4.rs b/src/test/run-fail/overflowing-rsh-4.rs index a8d3b69392a..ed1191849e5 100644 --- a/src/test/run-fail/overflowing-rsh-4.rs +++ b/src/test/run-fail/overflowing-rsh-4.rs @@ -5,6 +5,7 @@ // truncation does not sidestep the overflow checking. #![warn(exceeding_bitshifts)] +#![warn(const_err)] fn main() { // this signals overflow when checking is on |
