Skip to content

Commit b3234a3

Browse files
committed
[const-prop] Handle MIR Rvalue::Box
1 parent ea78010 commit b3234a3

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

src/librustc_mir/transform/const_prop.rs

+1-18
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
};
@@ -459,23 +459,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
459459
) -> Option<Const<'tcx>> {
460460
let span = source_info.span;
461461

462-
// if this isn't a supported operation, then return None
463-
match rvalue {
464-
Rvalue::NullaryOp(NullOp::Box, _) => return None,
465-
466-
Rvalue::Use(_) |
467-
Rvalue::Len(_) |
468-
Rvalue::Repeat(..) |
469-
Rvalue::Aggregate(..) |
470-
Rvalue::Discriminant(..) |
471-
Rvalue::Cast(..) |
472-
Rvalue::NullaryOp(..) |
473-
Rvalue::CheckedBinaryOp(..) |
474-
Rvalue::Ref(..) |
475-
Rvalue::UnaryOp(..) |
476-
Rvalue::BinaryOp(..) => { }
477-
}
478-
479462
// perform any special checking for specific Rvalue types
480463
if let Rvalue::UnaryOp(op, arg) = rvalue {
481464
trace!("checking UnaryOp(op = {:?}, arg = {:?})", op, arg);

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

+53
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)