Skip to content

Commit 79c5858

Browse files
committed
[const-prop] Handle MIR Rvalue::Box
1 parent 81fa591 commit 79c5858

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

src/librustc_mir/transform/const_prop.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc::hir::def::DefKind;
88
use rustc::hir::def_id::DefId;
99
use rustc::mir::{
1010
AggregateKind, Constant, Location, Place, PlaceBase, Body, Operand, Rvalue,
11-
Local, NullOp, UnOp, StatementKind, Statement, LocalKind,
11+
Local, UnOp, StatementKind, Statement, LocalKind,
1212
TerminatorKind, Terminator, ClearCrossCrate, SourceInfo, BinOp,
1313
SourceScope, SourceScopeLocalData, LocalDecl, BasicBlock,
1414
};
@@ -434,23 +434,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
434434
) -> Option<Const<'tcx>> {
435435
let span = source_info.span;
436436

437-
// if this isn't a supported operation, then return None
438-
match rvalue {
439-
Rvalue::NullaryOp(NullOp::Box, _) => return None,
440-
441-
Rvalue::Use(_) |
442-
Rvalue::Len(_) |
443-
Rvalue::Repeat(..) |
444-
Rvalue::Aggregate(..) |
445-
Rvalue::Discriminant(..) |
446-
Rvalue::Cast(..) |
447-
Rvalue::NullaryOp(..) |
448-
Rvalue::CheckedBinaryOp(..) |
449-
Rvalue::Ref(..) |
450-
Rvalue::UnaryOp(..) |
451-
Rvalue::BinaryOp(..) => { }
452-
}
453-
454437
// perform any special checking for specific Rvalue types
455438
if let Rvalue::UnaryOp(op, arg) = rvalue {
456439
trace!("checking UnaryOp(op = {:?}, arg = {:?})", op, arg);

src/test/mir-opt/const_prop/boxes.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// compile-flags: -O
2+
3+
#![feature(box_syntax)]
4+
5+
// Note: this test verifies that we, in fact, do not const prop `box`
6+
7+
fn main() {
8+
let x = *(box 42) + 0;
9+
}
10+
11+
// END RUST SOURCE
12+
// START rustc.main.ConstProp.before.mir
13+
// bb0: {
14+
// ...
15+
// _4 = Box(i32);
16+
// (*_4) = const 42i32;
17+
// _3 = move _4;
18+
// ...
19+
// _2 = (*_3);
20+
// _1 = Add(move _2, const 0i32);
21+
// ...
22+
// drop(_3) -> [return: bb2, unwind: bb1];
23+
// }
24+
// bb1 (cleanup): {
25+
// resume;
26+
// }
27+
// bb2: {
28+
// ...
29+
// _0 = ();
30+
// ...
31+
// }
32+
// END rustc.main.ConstProp.before.mir
33+
// START rustc.main.ConstProp.after.mir
34+
// bb0: {
35+
// ...
36+
// _4 = Box(i32);
37+
// (*_4) = const 42i32;
38+
// _3 = move _4;
39+
// ...
40+
// _2 = (*_3);
41+
// _1 = Add(move _2, const 0i32);
42+
// ...
43+
// drop(_3) -> [return: bb2, unwind: bb1];
44+
// }
45+
// bb1 (cleanup): {
46+
// resume;
47+
// }
48+
// bb2: {
49+
// ...
50+
// _0 = ();
51+
// ...
52+
// }
53+
// END rustc.main.ConstProp.after.mir

0 commit comments

Comments
 (0)