1
Fork 0

Fix const_err with -(-0.0)

This commit is contained in:
Yuki Okushi 2019-09-01 22:05:50 +09:00
parent d0677b9abc
commit 35c9e5f122
4 changed files with 13 additions and 27 deletions

View file

@ -6,7 +6,7 @@ use std::cell::Cell;
use rustc::hir::def::DefKind;
use rustc::mir::{
AggregateKind, Constant, Location, Place, PlaceBase, Body, Operand, Rvalue,
Local, NullOp, UnOp, StatementKind, Statement, LocalKind, Static, StaticKind,
Local, NullOp, StatementKind, Statement, LocalKind, Static, StaticKind,
TerminatorKind, Terminator, ClearCrossCrate, SourceInfo, BinOp, ProjectionElem,
SourceScope, SourceScopeLocalData, LocalDecl,
};
@ -407,18 +407,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
let arg = self.eval_operand(arg, source_info)?;
let val = self.use_ecx(source_info, |this| {
let prim = this.ecx.read_immediate(arg)?;
match op {
UnOp::Neg => {
// Need to do overflow check here: For actual CTFE, MIR
// generation emits code that does this before calling the op.
if prim.to_bits()? == (1 << (prim.layout.size.bits() - 1)) {
throw_panic!(OverflowNeg)
}
}
UnOp::Not => {
// Cannot overflow
}
}
// Now run the actual operation.
this.ecx.unary_op(op, prim)
})?;

View file

@ -13,7 +13,6 @@ fn black_box<T>(_: T) {
fn main() {
let a = -std::i8::MIN;
//~^ ERROR const_err
let b = 200u8 + 200u8 + 200u8;
//~^ ERROR const_err
let c = 200u8 * 4;

View file

@ -1,8 +1,8 @@
error: this expression will panic at runtime
--> $DIR/const-err2.rs:15:13
--> $DIR/const-err2.rs:16:13
|
LL | let a = -std::i8::MIN;
| ^^^^^^^^^^^^^ attempt to negate with overflow
LL | let b = 200u8 + 200u8 + 200u8;
| ^^^^^^^^^^^^^ attempt to add with overflow
|
note: lint level defined here
--> $DIR/const-err2.rs:8:9
@ -11,28 +11,22 @@ LL | #![deny(const_err)]
| ^^^^^^^^^
error: this expression will panic at runtime
--> $DIR/const-err2.rs:17:13
|
LL | let b = 200u8 + 200u8 + 200u8;
| ^^^^^^^^^^^^^ attempt to add with overflow
error: this expression will panic at runtime
--> $DIR/const-err2.rs:19:13
--> $DIR/const-err2.rs:18:13
|
LL | let c = 200u8 * 4;
| ^^^^^^^^^ attempt to multiply with overflow
error: this expression will panic at runtime
--> $DIR/const-err2.rs:21:13
--> $DIR/const-err2.rs:20:13
|
LL | let d = 42u8 - (42u8 + 1);
| ^^^^^^^^^^^^^^^^^ attempt to subtract with overflow
error: index out of bounds: the len is 1 but the index is 1
--> $DIR/const-err2.rs:23:14
--> $DIR/const-err2.rs:22:14
|
LL | let _e = [5u8][1];
| ^^^^^^^^
error: aborting due to 5 previous errors
error: aborting due to 4 previous errors

View file

@ -0,0 +1,5 @@
// run-pass
fn main() {
let _ = -(-0.0);
}