Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix const_err with -(-0.0) #64063

Merged
merged 7 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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 => {
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
// 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)
})?;
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/consts/const-err2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 7 additions & 13 deletions src/test/ui/consts/const-err2.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

5 changes: 5 additions & 0 deletions src/test/ui/consts/issue-64059.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// run-pass

fn main() {
let _ = -(-0.0);
}