Skip to content

Commit

Permalink
[const-prop] Handle MIR Rvalue::Box
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleywiser committed Sep 30, 2019
1 parent ea78010 commit b3234a3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 18 deletions.
19 changes: 1 addition & 18 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc::hir::def::DefKind;
use rustc::hir::def_id::DefId;
use rustc::mir::{
AggregateKind, Constant, Location, Place, PlaceBase, Body, Operand, Rvalue,
Local, NullOp, UnOp, StatementKind, Statement, LocalKind,
Local, UnOp, StatementKind, Statement, LocalKind,
TerminatorKind, Terminator, ClearCrossCrate, SourceInfo, BinOp,
SourceScope, SourceScopeLocalData, LocalDecl, BasicBlock,
};
Expand Down Expand Up @@ -459,23 +459,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
) -> Option<Const<'tcx>> {
let span = source_info.span;

// if this isn't a supported operation, then return None
match rvalue {
Rvalue::NullaryOp(NullOp::Box, _) => return None,

Rvalue::Use(_) |
Rvalue::Len(_) |
Rvalue::Repeat(..) |
Rvalue::Aggregate(..) |
Rvalue::Discriminant(..) |
Rvalue::Cast(..) |
Rvalue::NullaryOp(..) |
Rvalue::CheckedBinaryOp(..) |
Rvalue::Ref(..) |
Rvalue::UnaryOp(..) |
Rvalue::BinaryOp(..) => { }
}

// perform any special checking for specific Rvalue types
if let Rvalue::UnaryOp(op, arg) = rvalue {
trace!("checking UnaryOp(op = {:?}, arg = {:?})", op, arg);
Expand Down
53 changes: 53 additions & 0 deletions src/test/mir-opt/const_prop/boxes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// compile-flags: -O

#![feature(box_syntax)]

// Note: this test verifies that we, in fact, do not const prop `box`

fn main() {
let x = *(box 42) + 0;
}

// END RUST SOURCE
// START rustc.main.ConstProp.before.mir
// bb0: {
// ...
// _4 = Box(i32);
// (*_4) = const 42i32;
// _3 = move _4;
// ...
// _2 = (*_3);
// _1 = Add(move _2, const 0i32);
// ...
// drop(_3) -> [return: bb2, unwind: bb1];
// }
// bb1 (cleanup): {
// resume;
// }
// bb2: {
// ...
// _0 = ();
// ...
// }
// END rustc.main.ConstProp.before.mir
// START rustc.main.ConstProp.after.mir
// bb0: {
// ...
// _4 = Box(i32);
// (*_4) = const 42i32;
// _3 = move _4;
// ...
// _2 = (*_3);
// _1 = Add(move _2, const 0i32);
// ...
// drop(_3) -> [return: bb2, unwind: bb1];
// }
// bb1 (cleanup): {
// resume;
// }
// bb2: {
// ...
// _0 = ();
// ...
// }
// END rustc.main.ConstProp.after.mir

0 comments on commit b3234a3

Please sign in to comment.